1、UILabel

 NSString *str = @"字符串大小";
UIFont *font = [UIFont fontWithName:@"Arial" size:50.0f];
CGSize size = CGSizeMake(, );
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
[label setNumberOfLines:];
CGSize labelsize = [str sizeWithFont:font constrainedToSize:size lineBreakMode:UILineBreakModeCharacterWrap];
label.frame = CGRectMake(, , labelsize.width, labelsize.height);
label.textColor = [UIColor blackColor];
label.text = str;
label.font = font;
[self.view addSubview:label];

UILabel主要属性:

  text:设置UILabel的文本内容,NSString类型;

  font:设置文本的字体,UIFont类型;

  textColor:设置文本的颜色,UIColor类型;

  lineBreakMode:设置折行的模式,UILineBreakMode类型,一般为UILineBreakModeWordWrap;

  textAlignment:设置文本的对齐方式,UITextAlignment,有左、中、右

2、UIButton

继承于UIControl基类

UIButton缺省是圆角按钮,还有图片按钮、Info light、Info dark、Contack add、Detail disclosure

Button的点击事件中获取点击Button对象

 - (IBAction) buttonClick:(id)sender
{
//将sender强制转换成Button类型,获取哪个按钮触发的点击事件
UIButton *button = (UIButton *)sender;
.
.
.
}

- (void) addTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents:

  给按钮增加一个按钮事件的处理函数

- (void) removeTarget:(id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents:

  删除按钮的事件处理函数

手动创建Button

  手动创建Button,并且增加按钮点击事件

  UIControlEventTouchUpInside就是当手指点击按钮后离开屏幕的事件

 UIButton *button  = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button.frame = CGRectMake(, , , );
[button setTitle:@"按钮" forState:UIControlStateNormal];
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
button.tag = ;

tag是唯一识别每个按钮的属性

IBAction实际上就是一个void类型,只不过IBAction可以让Interface Builder知道这是一个按钮的点击事件。

3、NSDatePicker

1、NSDate类:是系统一个日期、时间类。

+(id)date:返回当前的日期、时间;

+(id)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs:返回未来secs秒后的日期、时间;

+(id)distantFuture:未来永远达不到的时间;

+(id)distantPast:过去的时间。

2、NSDateFormatter

 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"YYYY-MM-dd"];
NSString *d1 = [dateFormatter stringFromDate:date];
NSLog(@"date is %@", d1);  //输出2013-10-26 [dateFormatter setDateFormat:@"YYYY年MM月dd日"];
NSString *d2 = [dateFormatter stringFromDate:date];
NSLog(@"date is %@", d2);  //输出2011年11月24日

3、NSCalendar:得到当前日期、时间

 NSDate *date = [NSDate date];
NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:date];

设置当前日期、时间:
-(void) setYear:(NSInteger)v;

-(void) setMonth:(NSInteger)v;

-(void) setDay:(NSInteger)v;

-(void)setHour:(NSInteger)v;

-(void)setMinute(NSInteger)v;

-(void)setSecond:(NSInteger)v;

4、UIDatePicker

UIDatePicker事件处理:

UIControlEventValueChanged:UIDatePicker每次值改变时就会触发该事件

事件处理方式:

 [datePicker addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];

4、UIPickerView

1、UIPickerView常用的方法:

UIPickerView代理:

 @property(nonatomic, assign) id<UIPickerViewDelegate> delegate;
@property(nonatomic, assign)id<UIPickerViewDataSource> dataSource;

delegate定义了UIPickerView的外观和属性;
dataSource定义了UIPickerView的数据源和定制内容

- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

  返回component列、row行的一个UIView,这里只有在定制的情况下才有效,其他情况返回nil;

- (void)reloadAllComponets;

- (void)reloadComponent:(NSInteger)component;

  重新装载整个UIPickerView所有列的数据和指定列的数据;

- (void)selectROw:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;

  选中UIPickerView中component列、row行,也就是让改行滚动到中央;

- (void)(NSInteger)selectedRowInComponent:(NSInteger)component;

  返回指定列component中选中的行,没有选中返回-1;

- (NSInteger)numberOfComponentsInPickerView;

  返回UIPickerView一共有几列;

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponet:(NSInteger)component;

  返回指定的component列有几行数据;

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;

  返回UIPickerView中component列的宽度;

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponnet:(NSInteget)component;

  返回UIPickerView中component列中每行的高度;

- (void)pickerView:(UIPickerView *) pickView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;

  当列component、行row选中的回调函数;

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;

  标准的UIPickerView内容,只有字符串;

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

  自定义UIPickerView内容,给每一个行、列设置一个UIView对象。(PS:上面两个方法只能二选一)

2、UIPickerViewDelegate定制:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;

  自定义的UIPickerView内容,给每一个列、行设置一个UIView对象。

这里为列component、行row返回一个UIView用来显示在UIPickerView中。reusingView:(UIView *)view是iOS内核传入一个缓存的UIView。在程序中可以不用分配UIView,而可以重用iOS传过来的view。

iOS开发之iOS界面UI的更多相关文章

  1. 李洪强iOS开发之iOS社区收集

    李洪强iOS开发之iOS社区收集 项目 简述 github 全球最大的代码仓库,无论是iOS开发还是Android开发没有人不知道这个网站,它也是一个社区,你可以去follow(关注)某些人或公司. ...

  2. 李洪强iOS开发之iOS工具收集

    李洪强iOS开发之iOS工具收集 项目 简述 日期 我是怎么慢慢变懒的 : Jenkins + 蒲公英 使用Jenkins + 蒲公英使得项目打包给测试人员自动化,大大节省了劳动力 2015.04.1 ...

  3. 李洪强iOS开发之iOS学习方法收集

    李洪强iOS开发之iOS学习方法收集 在这里收集一些iOS学习方法,会不断更新 项目 简述 日期 一年多iOS开发总结 作者总结了自己一年多的iOS学习经验,对于iOS初学者来说很多地方是可以借鉴的 ...

  4. 李洪强iOS开发之iOS好文章收集

    李洪强iOS开发之iOS好文章收集 该文收集朋友们转发或自己的写的技术文章,如果你也有相关的好文章,欢迎留言,当好文章多的时候,我会对这些好文章进行分门别类 文章 简述 日期 直播服务配置 使用 ng ...

  5. 李洪强IOS开发之iOS好项目收集

    李洪强IOS开发之iOS好项目收集 在这里收集一些最近出现的比较实用好玩的框架或者项目,会不断更新 项目 简述 日期 SCTableViewCell 类似与QQ侧滑删除Cell的Demo 201501 ...

  6. 李洪强iOS开发之iOS技术博客

    李洪强iOS开发之iOS技术博客 注意:访问博客请直接点击博客,不要点击后面的RSS地址 博客地址 RSS地址 南峰子的技术博客   剑尖博客   图拉鼎   Henry Lee   Dev Talk ...

  7. iOS开发之iOS程序偏好设置(Settings Bundle)的使用

    目录[-] 1.添加设置项 2.设置的控件 3.编辑设置项的文件 4.在程序中获取Settings 和写入Settings 添加UI 5.实现读取设置和保存代码 在Android手机上, 在某个程序里 ...

  8. IOS开发之iOS深浅拷贝

    这里主要侧重于集合类的深浅拷贝,主要事因为工作的时候遇到这个问题. 有不足的地方欢迎指正 首先我们需要有这样的一个前提: [array addObject:obj]; 这样obj的引用计数会增加1,如 ...

  9. iOS开发之iOS程序的启动过程

    程序启动的完整过程: (1)main函数 (2)UIApplicationMain * 创建UIApplication对象 * 创建UIApplication的delegate对象 (3)delega ...

随机推荐

  1. redis数据类型(四)list类型

    一.list类型 list是一个链表结构,可以理解为一个每个子元素都是 string 类型的双向链表. 主要功能是push.pop.获取一个范围的所有值等. 操作中key理解为链表的名字. 二.Lis ...

  2. 从父子组件的mounted钩子的同步执行与页面的异步渲染看nextTick的用法

    最近复习vue的时候遇到了一个很奇怪的问题,我们直接从实例中看: <div id="app"> <child ref="child">& ...

  3. Windows远程协助相关汇总

    正常情况下要勾选一个 复选框 ,再确保三个服务启动 https://jingyan.baidu.com/article/ca00d56c4c62bce99febcf11.html https://ji ...

  4. iOS开源项目周报0119

    由OpenDigg 出品的iOS开源项目周报第六期来啦.我们的iOS开源周报集合了OpenDigg一周来新收录的优质的iOS开源项目,方便iOS开发人员便捷的找到自己需要的项目工具等. Sharaku ...

  5. [转] 常用的sql server规范

      常见的字段类型选择 1.字符类型建议采用varchar/nvarchar数据类型 2.金额货币建议采用money数据类型 3.科学计数建议采用numeric数据类型 4.自增长标识建议采用bigi ...

  6. 教你用go freetype根据用户昵称生成头像

    最近需要为用户服务添加一些新功能,其中就包括在注册时根据用户昵称生成头像这一点. 由于用户服务是用golang写的,google来google去都只找到freetype一个比较简单好用的库,其他比如I ...

  7. FileSystemWatcher 监视指定目录中的变更

    .Net框架类库中的FileSystemWatcher如它的名称一样是一个用于监视文件系统变化的一个控件.使用 FileSystemWatcher 监视指定目录中的更改.可监视指定目录中的文件或子目录 ...

  8. 十一、curator recipes之联锁InterProcessMultiLock

    简介 curator实现了一个类似容器的锁InterProcessMultiLock,它可以把多个锁包含起来像一个锁一样进行操作,简单来说就是对多个锁进行一组操作.当acquire的时候就获得多个锁资 ...

  9. 时间复杂度为O(logN)的常用算法

    时间复杂度为O(logN)的常用算法 折半查找 /* * 折半查找 * 默认查找的数组已经排过序 */ public static int binarySearch(int[] a,int x){ i ...

  10. 自己写的一个nodejs查找文件模块-node-find-all-files

    最近在折腾着用node-webkit搭建一个工具,其中要查找路径下的所有文件然后再进行压缩等操作,于是进写了这样的一个模块.代码如下: /* 输入目录找出目录下的所有文件,包括文件夹 */ /* 依赖 ...