OC常用入门代码

OC常用入门代码

ID:37325673

大小:372.46 KB

页数:29页

时间:2019-05-21

OC常用入门代码_第1页
OC常用入门代码_第2页
OC常用入门代码_第3页
OC常用入门代码_第4页
OC常用入门代码_第5页
资源描述:

《OC常用入门代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、常用代码整理:Xcode6,引入viewController代码:1.在Appdelegate先引入ViewController头文件2.ViewControllervc=(ViewControlleralloc)init;Self.window.rootViewController=vc;然后vc就代表ViewController对象,就可以调用其属性和方法了。一般用通知来取代上面的写法://发送通知[[[[NSNotificationCenterdefaultCenter]]postNotificationName:通知名object::nil];//接受通知//IB创建的对象调用in

2、itWithCoder要复写方法;-(instancetype)initWithCoder(NSCoder*)coder{self=[superinitWithCoder:coder];if(self){[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(method)name:@”….”object:nil];}returnself;}UILabel多行文字自动换行(自动折行)UIView*footerView=[[UIViewalloc]initWithFrame:CGRectMake(10,10

3、0,300,180)];UILabel*label=[[UILabelalloc]initWithFrame:CGRectMake(10,100,300,150)];label.text=@"whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?whereareyou?";//清空背景颜色label.backgroundColor=[UIColorclearColor];//设置字体颜色为白色label.textColor=[UI

4、ColorwhiteColor];//文字居中显示label.textAlignment=UITextAlignmentCenter;//自动折行设置label.lineBreakMode=UILineBreakModeWordWrap;label.numberOfLines=0;iOS的UILabel设置居上对齐,居中对齐,居下对齐在iOS中默认的UILabel中的文字在竖直方向上只能居中对齐,博主参考国外网站,从UILabel继承了一个新类,实现了居上对齐,居中对齐,居下对齐。具体如下:typedef enum  {      VerticalAlignmentTop = 0, // 

5、default      VerticalAlignmentMiddle,      VerticalAlignmentBottom,  } VerticalAlignment;  @interface myUILabel : UILabel  {  @private  VerticalAlignment _verticalAlignment;  }    @property (nonatomic) VerticalAlignment verticalAlignment;    @end  @implementation myUILabel  @synthesize verticalAli

6、gnment = verticalAlignment_;    - (id)initWithFrame:(CGRect)frame {      if (self = [super initWithFrame:frame]) {          self.verticalAlignment = VerticalAlignmentMiddle;      }      return self;  }    - (void)setVerticalAlignment:(VerticalAlignment)verticalAlignment {      verticalAlignment_ =

7、 verticalAlignment;      [self setNeedsDisplay];  }    - (CGRect)textRectForBounds:(CGRect)bounds limitedToNumberOfLines:(NSInteger)numberOfLines {  1.    CGRect textRect = [super textRectForBounds:bounds limited

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。