开发者

How can I customize a single edge of a UIView?

I know by setting the borderWidth and borderColor property of the layer of an UIView allo开发者_高级运维w me to customize the whole border.But now I just want to change an edge of the border, can anyone know how to do that?


I think an easy solution is to add a sub layer on your view's CALayer to simulate a border, like:

float borderWidth = 5.0;
CALayer *mockBorder = [CALayer layer];
[mockBorder setBorderColor:[[UIColor blueColor] CGColor]];
[mockBorder setBorderWidth:borderWidth];
[mockBorder setFrame:CGRectMake(-1.0 * borderWidth,
                                0.0,
                                yourView.frame.size.width + 2 * borderWidth,
                                yourView.frame.size.height + borderWidth)];
[[yourView layer] addSublayer:mockBorder];

The sample above simulates a up-only-border. By tweaking the parameters in CGRectMake you can create various combinations such as up+left, up+down, etc.

Don't forget to update the frame of the sub layer when the screen rotates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜