-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[Touches anyObject];
if (touch.tapCount >=1) {
[chi resignFirstResponder];
[meter resignFirstResponder];
[feet resignFirstResponder];
}
}
二、UILabel的行间距
UILabel *label = [[UILabel alloc] initWithFrame:labelFrame];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:textColor];
[label setNumberOfLines:0];
label.font = textFont;
NSString *labelText = @"我是内容,我是内容,我是内容,我是内容,我是内容。";NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:LINESPACE];//调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
label.attributedText = attributedString;
[contentView addSubview:label];
[label sizeToFit];
三、label的动态size
- (CGSize)labelAutoCalculateRectWith:(NSString*)text FontSize:(CGFloat)fontSize MaxSize:(CGSize)maxSize
{
NSMutableParagraphStyle* paragraphStyle = [[NSMutableParagraphStyle alloc]init];
paragraphStyle.lineBreakMode=NSLineBreakByWordWrapping;
NSDictionary* attributes =@{NSFontAttributeName:[UIFont fontWithName:@"MicrosoftYaHei" size:fontSize],NSParagraphStyleAttributeName:paragraphStyle.copy};
CGSize labelSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
labelSize.height=ceil(labelSize.height);
return labelSize;
}
四、判断设备
1、设备名称
return [UIDevice currentDevice].name;
2、设备型号,只可得到是何设备,无法得到是第几代设备
return [UIDevice currentDevice].model;
3、系统版本型号,如iPhone OS
return [UIDevice currentDevice].systemVersion;
4、系统版本名称,如6.1.3
return [UIDevice currentDevice].systemName;
5、判断是否为iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
6、判断是否为iPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
7、判断是否为ipod
#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])
8、判断是否为iPhone5
#define IS_IPHONE_5_SCREEN [[UIScreen mainScreen] bounds].size.height >= 568.0f && [[UIScreen mainScreen] bounds].size.height < 1024.0f
<span style="font-size:14px;">- (void)viewWillAppear:(BOOL)animated</span><span style="font-size:12px;">
{</span>
<span style="white-space: pre;"><span style="font-size:12px;"><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: Menlo;">1、</span><span style="color: rgb(66, 176, 92); font-family: 'Heiti SC Light'; letter-spacing: 0.5px; line-height: 22.5px;">设备名称</span></span></span><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"> NSLog(@"%@",[UIDevice currentDevice].name);</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="font-family: Menlo; color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px;">2、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">设备型号,只可得到是何设备,无法得到是第几代设备</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"> NSLog</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">(</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">@"%@"</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">,</span><span style="color: rgb(0, 204, 204); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">[UIDevice currentDevice].model</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"></span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">);</span>
</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="font-family: Menlo; color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px;">3、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">系统版本型号</span><span style="font-family: Menlo; color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px;">,</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">如</span><span style="font-family: Menlo; color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px;">iPhone OS</span>
</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"> NSLog</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">(</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">@"%@"</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">,</span><span style="color: rgb(0, 204, 204); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">[UIDevice currentDevice].systemVersion</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"></span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">);</span>
</span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: Menlo;">4、</span><span style="color: rgb(66, 176, 92); font-family: 'Heiti SC Light'; letter-spacing: 0.5px; line-height: 22.5px;">系统版本名称,如</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: Menlo;">6.1.3</span>
</span></span></span></p><p style="margin-top: 0px; margin-bottom: 0px; font-family: Menlo;"><span style="color:#333333;"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"> NSLog</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">(</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">@"%@"</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">,</span><span style="color: rgb(0, 204, 204); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">[UIDevice currentDevice].systemName</span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);"></span><span style="color: rgb(51, 51, 51); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px; white-space: pre; background-color: rgb(240, 240, 240);">);</span>
</span></span></span></p>
<span style="font-size:12px;">
</span>
<span style="font-size:12px;"><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">5、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">判断是否为</span><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">iPhone</span>
NSLog(@"%d",(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone));</span>
<span style="font-size:12px;"><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">6、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">判断是否为</span><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">iPad</span>
</span><pre name="code" class="objc" style="letter-spacing: 0.5px; line-height: 22.5px;"><span style="font-size:12px;"> NSLog(@"%d",<span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;"><span style="color:#666666;">(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)</span></span>);</span>
<span style="font-size:12px;"><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">7、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">判断是否为</span><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">ipod</span>
</span>
<pre name="code" class="objc" style="letter-spacing: 0.5px; line-height: 22.5px;"><span style="font-size:12px;"> NSLog(@"%d",<span style="color:#333333;"><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">([[[UIDevice currentDevice] model] isEqualToString:@</span><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">"iPod touch"</span><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">])</span></span>);</span>
<span style="font-size:12px;"><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">8、</span><span style="color: rgb(66, 176, 92); letter-spacing: 0.5px; line-height: 22.5px; font-family: 'Heiti SC Light';">判断是否为</span><span style="color: rgb(66, 176, 92); font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">iPhone5</span>
</span>
<pre name="code" class="objc" style="letter-spacing: 0.5px; line-height: 22.5px;"><span style="font-size:12px;"> NSLog(@"%d",<span style="color:#333333;"><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">[[UIScreen mainScreen] bounds].size.height >= </span><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">568.0f</span><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;"> && [[UIScreen mainScreen] bounds].size.height < </span><span style="font-family: Menlo; letter-spacing: 0.5px; line-height: 22.5px;">1024.0f</span></span>);</span>
}