1.利用plist文件创建模型
1.1如果发现系统自带的cell不够用 那就要自定义cell
1.1.1一般自定义cell需要创建2个模型
第一个存放plist里面的模型数据
第二个存放内空间的尺寸
在这里引入一个怎么把文字放到给定好尺寸的方法 叠放层次首先是 按钮->文字 然后设置文字的内边距 比如说20 现在按钮和文字的排列
textView.contentEdgeInsets = UIEdgeInsetsMake(MJTextPadding, MJTextPadding, MJTextPadding, MJTextPadding);
然后把按钮的边框大小加上40(内边距的2倍) 这样文字就居中显示在按钮的中间
// 按钮最终的真实尺寸
CGSize textBtnSize = CGSizeMake(textRealSize.width + MJTextPadding * 2, textRealSize.height + MJTextPadding * 2);
接着是将文字放入美工做好的小图片中 ,这个时候需要考虑的问题是图片太小,要将文字全部放入会让图片变形失真。IOS采取了这样的方法 截取图片中心的一小部分然后让他平铺要被填充的单元
定义一个函数 resizableImage 在里面调用resizableImageWithCapInsets方法将最中心对点取出如何平铺 使图片不失真。
+ (UIImage *)resizableImage:(NSString *)name
{
UIImage *normal = [UIImage imageNamed:name];
CGFloat w = normal.size.width * 0.5;
CGFloat h = normal.size.height * 0.5;
return [normal resizableImageWithCapInsets:UIEdgeInsetsMake(h, w, h, w)];
}
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.allowsSelection = NO; // 不允许选中
监听事件的方式有3种
1.addtarget
2.delegate
3.NSNotificationCenter 调用通知就要dealloc
// 2.监听键盘的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillChangeFrame:) name:UIKeyboardWillChangeFrameNotification object:nil];
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillChangeFrame:(NSNotification *)note
{
// 0.取出键盘动画的时间
CGFloat duration = [note.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
// 1.取得键盘最后的frame
CGRect keyboardFrame = [note.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
}
NSDate *now = [NSDate date];
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"HH:mm";
// NSDate ---> NSString
// NSString ---> NSDate
// fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
// 2014-08-09 15:45:56
// 09/08/2014 15:45:56
msg.time = [fmt stringFromDate:now];
要更改数据一定要刷新数据
[self.tableView reloadData];
键盘隐藏
/**
* 当开始拖拽表格的时候就会调用
*/
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
// 退出键盘
[self.view endEditing:YES];
}
@end