1.可以防止多个按钮同时点击出现崩溃,这个是一次只能点击一个按钮的方法
button.ExclusiveTouch = yes ;
imageVieww.clipsToBounds = yes;
imageView.contentMode = UIViewContentModeScaleAspectFill;
3.计算文本字体的宽度
lineImg.frame = CGRectMake(-1, self.oldPrice.frame.size.height/2,
[ self widthForLabel:self.oldPrice.text]+2, 0.5 );
- (float)widthForLabel:(NSString *)aString
{
if (nil == aString || [aString isEqualToString:@""] || [aString isEqualToString:@"null"] || [aString isEqual:[NSNull null]])
{
return 0;
}
else
{
CGSize size = [aString sizeWithFont:[UIFont systemFontOfSize:13] constrainedToSize:CGSizeMake(MAXFLOAT, 15)];
return size.width ;
}
4.手机号码和固话的正则表达式
// 判断手机或者电话号码是否正确
+ (BOOL) isValidateMobile:(NSString *)mobile
{
//手机号以13, 15,18开头,八个 \d 数字字符
NSString *phoneRegex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
//固话不加区号的
NSString * CT1 = @"^(0[0-9]{2,3}/-)?([2-9][0-9]{6,7})+(/-[0-9]{1,4})?$";
NSPredicate *regextestct1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT1];
// 固话加区号的
NSString * CT2 = @"^0(10|2[0-5789]|\\d{3})\\d{7,8}$";
NSPredicate *regextestct2 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT2];
if ([phoneTest evaluateWithObject:mobile] || [regextestct1 evaluateWithObject:mobile] || [regextestct2 evaluateWithObject:mobile])
{
return YES;
}
else
{
return NO;
}
}
5.字体高度
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, self.view.frame.size.width, 200 )];
[label setBackgroundColor:[UIColor blackColor]];
[label setTextColor:[UIColor whiteColor]];
[label setNumberOfLines:0];
NSString *labelText = @" 可以自己按照宽高,字体大小,来计算有多少行。。然后。。。每行画一个 UILabel 。。高度自己可以控制把这个写一个自定义的类。 ";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:labelText];
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:200];// 调整行间距
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [labelText length])];
label.attributedText = attributedString;
[self.view addSubview:label];
[label sizeToFit];
int page = 1;
if (isRefreshing) {
page = 1;
}
else {
if (self.items.count%MM_PER_PAGE_SIZE != 0) {
[systemMessageTableView endRefreshingAndReloadData];
return;
}
else {
page = (int)self.items.count/MM_PER_PAGE_SIZE+1 ;
}
}
7. 代理的正确写法
if(_delegate && [_delegaterespondsToSelector:@selector(GesPasswordViewLoginPassed:)]) {
[self.delegate GesPasswordViewLoginPassed:self ];8.tableView进去默认选中第一个
[_leftTableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionNone];
9.MBProgressHUD 的gitHub网址(非常好用)
https://github.com/jdg/MBProgressHUD
}
10.判断输入金额为正数,或者保留小数点后面两位的正则
- (BOOL) isValidateNumber:(NSString *)number
{
NSString *phoneRegex = @"[0-9]*[1-9][0-9]*";
NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
NSString *phoneRegex1 = @"^(([1-9]+)|([0-9]+\.[0-9]{1,2}))$";
NSPredicate *phoneTest1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex1];
if ([phoneTest evaluateWithObject:number] || [phoneTest1 evaluateWithObject:number])
{
return YES;
}
else
{
return NO;
}
}