发布于 2016-02-22 13:41:51 | 158 次阅读 | 评论: 0 | 来源: 分享
iOS苹果移动操作系统
苹果iOS是由苹果公司开发的移动操作系统。苹果公司最早于2007年1月9日的Macworld大会上公布这个系统,最初是设计给iPhone使用的,后来陆续套用到iPod touch、iPad以及Apple TV等产品上。
最近有一些比较流行的应用,界面都是圆角的。比如Memopad,Pinterest之类的,都是。
琢磨了一下,发现这个其实很简单。我们只需要在UIView上做点功夫就可以了。
创建一个UIView的Category,名为UIView+RoundCorner
,在头文件UIView+RoundCorner.h
中声明如下:
#import
@interface UIView (RoundCorner)
-(void)makeRoundedCorner:(CGFloat)cornerRadius;
@end
在实现文件UIView+RoundCorner.h
代码如下:
#import "UIView+RoundCorner.h"
@implementation UIView(RoundCorner)
-(void)makeRoundedCorner:(CGFloat)cornerRadius
{
CALayer *roundedlayer = [self layer];
[roundedlayer setMasksToBounds:YES];
[roundedlayer setCornerRadius:cornerRadius];
}
@end
对所有UIView或者其派生类,直接使用该方法即可,比如下面的代码让一个UIButton变圆角了:
[btn makeRoundedCorner:12.0f];
疗效如下(为了让疗效看起来更明显,我把按钮弄黑了):
只需要在ViewContolloer中调用这个方法就好了,比如:
[self.view makeRoundedCorner:12.0f];
如果你的ViewController在UITabBarController
中,你只需要调用这个方法就可以让整个界面所有的界面都变成圆角的。
比如
if (self.parentViewController) {
[self.parentViewController.view makeRoundedCorner:12.0f];
}
疗效如下: