自定义形状(倒T形)在iOS中与Uiview接壤 [英] Custom shaped (inverted T) bordered Uiview in iOS

查看:55
本文介绍了自定义形状(倒T形)在iOS中与Uiview接壤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在iOS上创建带有边框的Uiview的自定义形状(倒T形).我附上以下屏幕截图.我做了很多研究,发现了一种使用 UIBezierPath 的方法,该方法来自

I have to create a custom shaped (inverted T) bordered Uiview on iOS. I am attaching the screenshot below. I have researched a lot and I found a way using UIBezierPath from here.

但是我不知道将我的视图塑造成倒T形.

But I didn't get any idea to shape my view as inverted T shaped.

推荐答案

Phew ..最后,我做到了.我使用了两个UiViews子类(顶部和底部).

Phew.. Finally I have done it. I have used two UiViews subclasses (top & bottom).

我面临的主要挑战是边框,因为如果将边框设置为两个视图(顶部和底部),它将不会显示为单个容器项目. :)

The main challenge I faced was about the border, because if I set the border to my two views (top & bottom), it will not show as a single container item. :)

我完成的步骤:

创建了两个UiView子类.让我们调用 topView bottomView .

Created two UiView subclasses. Lets call topView and bottomView.

    TopView *topView = [[TopView alloc] initWithFrame:CGRectMake(220, 60, 200, 200)];
    [topView setBackgroundColor:[UIColor yellowColor]]; 
    [self.view addSubview:topView]; 

    BottomView *bottomView = [[BottomView alloc] initWithFrame:CGRectMake(130, 260, 380, 200)];
    [bottomView setBackgroundColor:[UIColor yellowColor]];
    bottomView.customShape = topView; //Set the custom shape as TopView to frame to draw the border.    
    [self.view addSubview:topView];

我已为 TopView 两个完整边框(底部,右侧),绘制了三个边框(顶部,右侧,左侧)通过覆盖 drawRect 方法,为 BottomView >两个局部边框(左上角,右上角).

I have drawn three borders (top,right,left) for TopView and two full borders (bottom, right), two partial borders (top left, top right) for BottomView through overriding the drawRect method.

此处中查看我的TopView类.

See my TopView class here.

此处中查看我的BottomView类.

See my BottomView class here.

感谢所有人.

输出:

这篇关于自定义形状(倒T形)在iOS中与Uiview接壤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆