如何在uiview中添加边框? [英] How to add a border inside a uiview?

查看:181
本文介绍了如何在uiview中添加边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个uiview,我想在这个UIVIew大约75%的UIView中添加一个边框。任何人都可以为此提供帮助。我可以得到解决方案在外面绘制边框。

I am having a uiview and I would like to add a border iside this UIVIew approximately 75 % of UIView. Could any one help with this. I could get the solution to draw the border outside.

推荐答案

那么你可以设置一个小的属性来对齐与外界的边界。它绘制与内部对齐,因为UIViews默认绘图操作在其边界内绘制。

Well there isn't simply a little property you can set to align the border to the outside. It draws aligned to the inside because the UIViews default drawing operations draw within its bounds.

想到的最简单的解决方案是扩展UIView的大小应用边框时的边框宽度:

The simplest solution that comes to mind would be to expand the UIView by the size of the border width when applying the border:

CGFloat borderWidth = 2.0f;

self.frame = CGRectInset(self.frame, -borderWidth, -borderWidth);
self.layer.borderColor = [UIColor yellowColor].CGColor;
self.layer.borderWidth = borderWidth;

这篇关于如何在uiview中添加边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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