iOS开发常用知识点二

2017-09-08  本文已影响13人  博士猫_BSM

tableView上面多出来20个像素,是因为自动布局的缘故,设置一下属性就可以解决问题

self.edgesForExtendedLayout = UIRectEdgeNone;

如果想数组进行倒序排列

NSMutableArray *array = [NSMutableArray arrayWithObjects:@“1”,@“2”,@“3”,nil];

NSArray *reversedArray = [[array reverseObjectEnumerator allObjects];

如果想scrollView不能上下滑动只能左右滑动下面设置可以实现

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{

Float oldY = 0.0;

[scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x,oldY)];

}

设置UILabel行间距和字间距

+(void)setLabelSpace:(UILabel*)label withValue:(NSString*)str withFont:(UIFont*)font{

NSMutableParagraphStyle*paraStyle = [[NSMutableParagraphStylealloc]init];

paraStyle.lineBreakMode=NSLineBreakByCharWrapping;

paraStyle.alignment=NSTextAlignmentLeft;

paraStyle.lineSpacing=UILABEL_LINE_SPACE;//设置行间距

paraStyle.hyphenationFactor=1.0;

paraStyle.firstLineHeadIndent=0.0;

paraStyle.paragraphSpacingBefore=0.0;

paraStyle.headIndent=0;

paraStyle.tailIndent=0;

//设置字间距NSKernAttributeName:@1.5f

NSDictionary*dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@0.0f};

NSAttributedString*attributeStr = [[NSAttributedStringalloc]initWithString:strattributes:dic];

label.attributedText= attributeStr;

}

5、计算UILabel的高度(带有行间距的情况)

+(CGFloat)getSpaceLabelHeight:(NSString*)str withFont:(UIFont*)font withWidth:(CGFloat)width {

NSMutableParagraphStyle*paraStyle = [[NSMutableParagraphStylealloc]init];

paraStyle.lineBreakMode=NSLineBreakByCharWrapping;

paraStyle.alignment=NSTextAlignmentLeft;

paraStyle.lineSpacing=UILABEL_LINE_SPACE;

paraStyle.hyphenationFactor=1.0;

paraStyle.firstLineHeadIndent=0.0;

paraStyle.paragraphSpacingBefore=0.0;

paraStyle.headIndent=0;

paraStyle.tailIndent=0;

NSDictionary*dic =@{NSFontAttributeName:font,NSParagraphStyleAttributeName:paraStyle,NSKernAttributeName:@0.0f};

CGSizesize = [strboundingRectWithSize:CGSizeMake(width,KHeight)options:NSStringDrawingUsesLineFragmentOriginattributes:diccontext:nil].size;

returnsize.height;

}

上一篇下一篇

猜你喜欢

热点阅读