- 可获得CGRectMake(0, 0, 200, 999) 条件下的label的rect
CGRect rectOfText = [self.popLabel textRectForBounds:CGRectMake(0, 0, 200, 999) limitedToNumberOfLines:0];
2.可在imageview的frame的基础下拉伸图片
self.imageview.image = [[UIImage imageNamed:@"SenderTextNodeBkg"] resizableImageWithCapInsets:UIEdgeInsetsMake(10, 10, 10, 10)];//拉伸图片
例子为上下左右都向里压缩10像素
3.键盘显示与收回时的通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillHide:) name:UIKeyboardWillHideNotification object:nil];
-(void)keyBoardWillShow:(NSNotification*)notification
{
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
UIViewAnimationOptions option = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] intValue];
CGFloat keyboard_H = keyboardFrame.size.height;
__weak typeof(self) weakself = self;
[UIView animateWithDuration:duration delay:0 options:option animations:^{
//上移键盘高度
weakself.chat_Tabv.frame = CGRectMake(0, 64-keyboard_H, iphone_w, iphone_h-64-tool_h);
weakself.chat_ToolV.frame = CGRectMake(0, iphone_h-tool_h-keyboard_H, iphone_w, tool_h);
} completion:^(BOOL finished) {
}];
}
4.tableview中插入行与数据
[self.chat_Tabv insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
调用后会自动调用一次heightForRow和CellForRow
5.tableView自动滑动到某一行
[self.chat_Tabv scrollToRowAtIndexPath:lastIndexPath atScrollPosition:UITableViewScrollPositionBottom animated:NO];
6.获取某字符串在text中的range
[text rangeOfString:@"张三睡得正香"]
7.获取字符串的高度与宽度
NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:font]};
CGSize size = CGSizeMake(width, CGFLOAT_MAX);
CGRect rect = [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
8.bringSubviewToFront 和 sendSubviewToBack
将一个UIView显示在最前面只需要调用其父视图的 bringSubviewToFront()方法。
将一个UIView层推送到背后只需要调用其父视图的 sendSubviewToBack()方法。
用第二层子视图 换 第一层子视图的位置 self.view是第0层
[self.view exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
5.tableView自动滑动到某一行
网友评论