iOS相关的UI最新知识点总结(二)

50.直接创建的tab记得设置数据源self.tableView.dataSource = self;

51. -(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section设置组尾标题

52. -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section设置组头标题

53.设置行高self.tableView.rowHeight = 100;这还是每行的高度一致的时候设置的(统一行高)

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath,单独设置行高

54. self.tableView.separatorColor = [UIColor redColor];

55.设置分隔线样式UITableViewCellSeparatorStyle

56. 分割线的内边距 上下是无效的, 左边会影响cell中文字的位置,右边不会影响cell中的控件self.tableView.separatorInsets

57. 给UITableView设置头和尾

设置头View 只有高度起作用

58. self.tableView.tableHeaderView = view;

self.tableView.tableFooterView = view; 设置尾View X 和 高度都有作用

59. UITableViewCell的常见属性

1:设置图片 cell.imageView.image

2.设置文本标题 cell.textLabel.text

3:设置详情描述标题 cell.detailTextLabel.text

60.设置右侧标签的图标cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;(系统提供好的),如果自己的图片可以设置cell.accessoryView = view;

61. cell.backgroundColor = [UIColor redColor];//cell的背景色

62. cell.selectedBackgroundView = view;//cell选中时的背景色时

63.重写set方法的时候,记得先给变量赋值

64. self.tableView.separatorStyle= UITableViewCellSeparatorStyleNone;通过这句话,可以去掉分隔线

65.设置tableView的style

self = [super initWithStyle:UITableViewStyleGrouped];

[[UITableView alloc] initWithFrame:(CGRect)frame style:(UITableViewStyle)style]

使用self.tableView.style = UITableViewStyleGrouped; 会出现错误,只读属性

66.字典转模型的时候,一般在最最容易获得字典数组的地方进行字典转模型

模型嵌套模型:模型里面的一个属性同时也是字典数组,在模型第一层KVC的时候,将获取到的值(字典数组属性)转化为模型数组,将模型数组作为属性保存到第一层模型里面

67.在设置动画切换上一张下一张时,通过设置全局变量index,通过不同的index来关联不同的界面数值,实现界面的更新

68.cell可以设置背景以及选中之后的背景

1)背景

    UIView *view = [[UIView alloc]init];

    view.frame = CGRectMake(20, 50, 10, 5);

    view.backgroundColor = [UIColor redColor];

cell.backgroundView = view;

2)选中背景

cell.selectedBackgroundView = view;

69.KVC--键值编码,可以忽视属性是否私有

70. tableView.separatorColor = [UIColor orangeColor];

设置分隔线的颜色

71.通过kvc的方式给属性赋值,

-(NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView{

//检查数组里面有无title属性,如没有,就遍历数组,取出数组里面的title属性的所有的值,组成新的数组返回

    return [self.carKindsArray valueForKey:@"title"];

}

72. 设置alertView

UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"修改名称" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"1",@"2", nil];//取消是0,剩下的一次加一

[alertView show];

73.设置alertView的输入框

alertView.alertViewStyle = UIAlertViewStylePlainTextInput;单个输入框的模式

UIAlertViewStyleSecureTextInput,单个加密输入框

UIAlertViewStyleLoginAndPasswordInput用户名密码输入框

UITextField *field = [alertView textFieldAtIndex:0];设置输入框的文字,从上面到下面索引为0、1、2。。

74. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex NS_DEPRECATED_IOS(2_0, 9_0)//输入框的按钮的点击事件,通过索引进行区分

75.tableView的刷新方式

1)[self.tableView reloadData];刷新所有

2)[self.tableView reloadRowsAtIndexPaths:@[self.indexPath] withRowAnimation:UITableViewRowAnimationRight];单行刷新

76.精确的延时工具

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{延时之后的操作}

77.一般设置间距,经常用到的值,采用宏定义例:#define padding 10

78.获取已经存在的尺寸的x,y信息

CGRectGetMaxX、CGRectGetMidY等等

79.通过字符串,以及字体的大小,设置字符串的长度

CGRect userImageViewBounds = [字符串 boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:字体值]} context:nil];

80.最新的弹框方式

UIAlertController * alertController=[UIAlertController alertControllerWithTitle:@"提示" message:@"恭喜你过关了" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction *actionOK = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil];

    UIAlertAction *actionCancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil];

   

    [alertController addAction:actionOK];

    [alertController addAction:actionCancle];

   

[self presentViewController:alertController animated:YES completion:nil];

81.一般定义c成为几种特别的分类,可以采取枚举的方式定义,下面是枚举定义的示例:typedef enum {

    CZMessageTypeMe = 0,

    CZMessageTypeOther

}CZMessageType;

82. control + command+方向上下不同的.m和.h之间

进行切换

83.为不可变数组添加元素,应当先转化为可变数组

 NSMutableArray *nmArray = self.tgArray;

 [nmArray addObject:tg];

 self.tgArray = nmArray;

84.调用代理方法或者是block回调时,应当先进行判断再调用方法

if ([self.delegate respondsToSelector:@selector(tgFooterLoadMoreData:)]) {

 [self.delegate tgFooterLoadMoreData:self];

}

85.

[[[NSBundle mainBundle]loadNibNamed:@"CZTgFooterView" owner:nil options:nil]lastObject];记得加last zhiObject

86.为什么使用frame模型的问题,因为heightForRow这个方法在cellForRow方法前面执行。里面的cell并未生成,但是必须返回cell的行高,所以需要通过模型数据先将cell的高度计算出来,返回

87. NSLog(@"%s",__func__);查看方法执行

88. -(instancetype)initWithStyle:(UITableViewCellStyle)style通常在c初始化方法里面只做两件事情

(1. 实例化子控件

(2. 将子控件添加到父控件中,并不会设置数据以及frame

89.通过字符串,判断占用的bounds的fang方式

CGRect messageBounds = [字符串 boundingRectWithSize:CGSizeMake(self.contentView.frame.size.width - 2*padding, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:一个字典 context:nil];

NSDictionary *传入的字典= @{NSFontAttributeName:[UIFont systemFontOfSize:15]};

90.一般使用frame模型之后,模型里main一般有数据模型,所以懒加载数据时,我们仅仅加载frame模型即可,通过frame模型里面的数据模型属性赋值,所以通过已经使用plist加载的好的数据模型,创建frame对象,创建frame模型数组,最终我们获得的是包涵数据模型的frame模型数组

  NSMutableArray *nmArray = [NSMutableArray array];

//2.1.2 遍历字典数组

for (NSDictionary *dict in _messageFrameArray) {

//2.1.3 字典转模型并添加到可变数组中

CZMessage *message = [CZMessage messageWithDict:dict];

// 创建CZMessageFrame模型

CZMessageFrame *messageFrame = [[CZMessageFrame alloc]init];

messageFrame.message = message;

//将frame模型添加到可变数组中

 [nmArray addObject:messageFrame];

}

//2.1.4 将存放为模型的可变数组,赋值给字典数组

_messageFrameArray = nmArray;

91.也是涉及到frame模型的使用,一般是用来获取行高的时候使用,

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return messageFrame.rowHeight }

92.通知的使用

1).创建通知

NSNotification *notification = [NSNotification notificationWithName:@"yule" object:sinaNews userInfo:@{@"奥斯卡":@"小李子终于不是打酱油的,拿到小金人了"(字典类型)}];

2).发布通知[notificationCenter postNotification:notification];

3)有必要监听消息的人注册消息监听

[notificationCenter addObserver:p1 selector:@selector(showNotifaction:) name:nil object:sinaNews];

4)接受到消息的监听着,调用已经定义好的方法

- (void)showNotifaction:(NSNotification *)notification{

NSDictionary *dict = notification.userInfo;

 NSLog(@"接收人 %@ , 接收到的消息 %@",self.name,dict[@"奥斯卡"]);

NSLog(@"接收人 %@ , 接收到的消息 %@",self.name,dict[@"朝鲜"]);

5).注销消息的监听

- (void)dealloc{

//ARC 非ARC -> MRC

//在非ARC中一定不要忘记

//    [super dealloc];

//销毁监听对象

 [[NSNotificationCenter defaultCenter]removeObserver:self];

}

93.也是源于通知的使用,键盘的监听(出现和消失)

[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeKeyBoard:) name:UIKeyboardWillShowNotification object:nil];

 [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeKeyBoard:) name:UIKeyboardWillHideNotification object:nil];

调用通知的方法

- (void)changeKeyBoard:(NSNotification *)notification{

NSLog(@"%@",notification);

//获取userInfo信息

NSDictionary *userInfo = notification.userInfo;//通过字典可以获得键盘的frame以及动画的时间

CGAffineTransform transForm = self.view.transform;

//获取移动的位置 屏幕的高度 - 最终显示的frame的Y = 移动的位置

//1. 获取键盘最终显示的y

NSValue *value = userInfo[UIKeyboardFrameEndUserInfoKey];

CGRect endFrame = [value CGRectValue];

CGFloat moveY = - (self.view.frame.size.height - endFrame.origin.y);

//移动

transForm = CGAffineTransformMakeTranslation(0, moveY);

//执行动画移动,时间为键盘动画的时间

 [UIView animateWithDuration:[userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue] animations:^{

self.view.transform = transForm;//通过键盘的位置,将view整体的位置进行移动

}];

}

94.获取当前的时间

NSDate *date = [NSDate date];

//时间格式化

NSDateFormatter *format = [[NSDateFormatter alloc]init];

//设置格式化的样式

format.dateFormat = @"HH:mm";

//按照样式转换NSDate

NSString *currentTime = [format stringFromDate:date];

95.使用textFiled点击输入按钮,return时会调用代理的方法

self.textField.delegate = self;

- (BOOL)textFieldShouldReturn:(UITextField *)textField{}

96. 清空textField信息

textField.text = @"";

97.滚动到tableView的最后一行的方法

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.messageFrameArray.count - 1 inSection:0];

[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

98.如果对于一个模块,有的存在有的不存在,可以设置它的状态是否隐藏,注意cell重用的问题

99.设置textField的左边有一段的输入边距

self.textField.leftView = view;

self.textField.leftViewMode = UITextFieldViewModeAlways;

100.在tableView的数据,展示方式发生改变的时候,记得刷新tableView

 

原文地址:https://www.cnblogs.com/chaoyueME/p/5557229.html