首页 > 移动平台 > 详细

iOS开发--根据文字动态调整按钮(UIButton)宽度

时间:2015-03-27 12:55:05      阅读:446      评论:0      收藏:0      [点我收藏+]
    CGRect mainBounds = [[UIScreen mainScreen] bounds];
    UIFont *font = [UIFont systemFontOfSize:15.0f];
    CGRect locationBtnFrame = self.locationButton.frame;
    
    CGFloat maxWidth = mainBounds.size.width - locationBtnFrame.origin.x;
    CGSize size = CGSizeMake(maxWidth, MAXFLOAT);
    CGSize theStringSize = [theText sizeWithFont:font
                               constrainedToSize:size
                                   lineBreakMode:self.locationButton.lineBreakMode];
    
    self.locationButton.frame = CGRectMake(locationBtnFrame.origin.x,
                                locationBtnFrame.origin.y,
                                theStringSize.width, locationBtnFrame.size.height);

iOS开发--根据文字动态调整按钮(UIButton)宽度

原文:http://blog.csdn.net/wang_lichun/article/details/44673683

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!