标签:
1、在UIView的子类中在视图即将显示的时候再次改变控件的位置
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect rect = _msgButton.frame;
rect.size.height = self.bounds.size.height -2*RMarginSize ;
_msgButton.frame = rect;
}
2、多少时间后执行再什么
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[hud dismiss];
});
3、获得登陆数据
NSString *loginDataPath = [NSHomeDirectory() stringByAppendingString:@"/Documents/login.data"];
NSData *loginData = [NSData dataWithContentsOfFile:loginDataPath];
NSDictionary *loginDataDic = [NSJSONSerialization JSONObjectWithData:loginData options:0 error:nil];
4、 获取字符串的宽度或高度
self.width = [self.taskNameLab.text boundingRectWithSize:CGSizeMake(200, 44) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18]} context:nil].size.width;
5、因为一般为了不让UIview的背景色不延伸到 navigationBar 下面
self.navigationController.navigationBar.translucent = NO;
或者
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}
6、键盘处理
#pragma 文本框委托方法
//当textField 开始编辑时调用的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
float offset = self.view.frame.size.height - (_Bottomview.frame.origin.y + _Bottomview.frame.size.height + 216 +40);
NSLog(@"offset = %lf",offset);
if (offset <= 0) {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.view.frame;
frame.origin.y = offset;
self.view.frame = frame;
}];
}
return YES;
}
//当textField 结束编辑时调用的方法
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
[UIView animateWithDuration:0.3 animations:^{
CGRect frame = self.view.frame;
frame.origin.y = 0.0;
self.view.frame = frame;
}];
return YES;
}
//按下Done按钮的调用方法,我们让键盘消失
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
NSString *info = _message.text;
NSLog(@"info = %@",info);
[textField resignFirstResponder];
return YES;
}
// 点击页面空白出 收取键盘
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
// [self.view endEditing:YES]; // 点击控制器View的区域会使得其他控件放弃第一响应者身份。
[textField resignFirstResponder];
}
7、定义宏,判断ios7
#define IOS7 [[[UIDevice currentDevice]systemVersion] floatValue] >= 7.0
//添加代码
if (IOS7)
{
self.edgesForExtendedLayout = UIRectEdgeNone; //视图控制器,四条边不指定
self.extendedLayoutIncludesOpaqueBars = NO; //不透明的操作栏<br> self.modalPresentationCapturesStatusBarAppearance = NO;
}
8、图片拉伸
// UIImageView 背景(块区域)拉伸图片
UIEdgeInsets imageInsets = UIEdgeInsetsMake(20, 50, 20, 10);
Image = [_tipImage resizableImageWithCapInsets:imageInsets resizingMode:UIImageResizingModeStretch];
UIImageView.image = Image;
// 只拉伸一个中间像素的方式
UIImage *img=[UIImage imageNamed:@"bubbleSelf.png"];
img=[img stretchableImageWithLeftCapWidth:15 topCapHeight:12];
UIImageView *imgView=[[UIImageView alloc]initWithImage:img];
[imgView setFrame:CGRectMake(10, 10, 200, 200)];
[self. view addSubview:imgView];
标签:
原文地址:http://www.cnblogs.com/tengquanzhou/p/4889869.html