ios开发小技巧
1.设置UILable 的行间距 和 计算带行间距的高度
/*
UILabel* 展示的控件
(NSString*)str 内容
withFont:(float)font 字体大小
WithSpace:(float)space 行间距
*/
//给UILabel设置行间距和字间距
-(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(float)font WithSpace:(float)space{
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = space;//设置行间距
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
//设置字间距 NSKernAttributeName:@1.5f
UIFont *tfont = [UIFont systemFontOfSize:font];
NSDictionary *dic = @{NSFontAttributeName:tfont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
NSAttributedString *attributeStr = [[NSAttributedString alloc] initWithString:str attributes:dic];
label.attributedText = attributeStr;
}
/*
计算UILabel的高度(带有行间距的情况)
(NSString*)str 内容
withFont:(float)font 字体大小
WithSpace:(float)space 行间距
(CGFloat)width UILable的宽度
*/
//计算UILabel的高度(带有行间距的情况)
-(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(float)font withWidth:(CGFloat)width WithSpace:(float)space{
NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
paraStyle.lineBreakMode = NSLineBreakByCharWrapping;
paraStyle.alignment = NSTextAlignmentLeft;
paraStyle.lineSpacing = space;
paraStyle.hyphenationFactor = 1.0;
paraStyle.firstLineHeadIndent = 0.0;
paraStyle.paragraphSpacingBefore = 0.0;
paraStyle.headIndent = 0;
paraStyle.tailIndent = 0;
UIFont *tfont = [UIFont systemFontOfSize:font];
NSDictionary *dic = @{NSFontAttributeName:tfont, NSParagraphStyleAttributeName:paraStyle, NSKernAttributeName:@1.5f
};
CGSize size = [str boundingRectWithSize:CGSizeMake(width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size;
returnsize.height;
}
2.禁止程序运行时自动锁屏
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
3.取消系统的返回手势
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
4.百度坐标跟火星坐标相互转换
//百度转火星坐标
+ (CLLocationCoordinate2D )bdToGGEncrypt:(CLLocationCoordinate2D)coord
{
double x = coord.longitude - 0.0065, y = coord.latitude - 0.006;
double z = sqrt(x * x + y * y) - 0.00002 * sin(y * M_PI);
double theta = atan2(y, x) - 0.000003 * cos(x * M_PI);
CLLocationCoordinate2D transformLocation ;
transformLocation.longitude = z * cos(theta);
transformLocation.latitude = z * sin(theta);
returntransformLocation;
}
//火星坐标转百度坐标
+ (CLLocationCoordinate2D )ggToBDEncrypt:(CLLocationCoordinate2D)coord
{
double x = coord.longitude, y = coord.latitude;
double z = sqrt(x * x + y * y) + 0.00002 * sin(y * M_PI);
double theta = atan2(y, x) + 0.000003 * cos(x * M_PI);
CLLocationCoordinate2D transformLocation ;
transformLocation.longitude = z * cos(theta) + 0.0065;
transformLocation.latitude = z * sin(theta) + 0.006;
returntransformLocation;
}
6.简单写出增、删、改、查的SQL语句
增: insert into tb_blogs(name, url) values('aaa','http://www.baidu.com');
删:deletefrom tb_blogs where blogid = 1;
改:update tb_blogs set url ='www.baidu.com'where blogid = 1;
查: select name, url from tb_blogs where blogid = 1;