如何得到自动布局后的控件,比如UILable,的高度宽度
2个回答
展开全部
在你的cell里面加一个UILable,你需要做的是计算你的内容的高度,然后在
heightForRowAtIndexPath里面设置你的cell的高度。这是一种方法: #define CELL_CONTENT_WIDTH
320.0f (你的cell的宽度) #define CELL_CONTENT_MARGIN 10.0f CGSize cons
heightForRowAtIndexPath里面设置你的cell的高度。这是一种方法: #define CELL_CONTENT_WIDTH
320.0f (你的cell的宽度) #define CELL_CONTENT_MARGIN 10.0f CGSize cons
展开全部
可以这样:
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:scrollView];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
NSString *vflH = @"H:|-10-[scrollView]-10-|";
NSDictionary *views = NSDictionaryOfVariableBindings(scrollView);
NSArray *constraintsH = [NSLayoutConstraint constraintsWithVisualFormat:vflH
options:kNilOptions
metrics:nil
views:views];
[NSLayoutConstraint activateConstraints:constraintsH];
NSString *vflV = @"V:|-74-[scrollView]-10-|";
NSArray *constraintsV = [NSLayoutConstraint constraintsWithVisualFormat:vflV
options:kNilOptions
metrics:nil
views:views];
[NSLayoutConstraint activateConstraints:constraintsV];
[scrollView layoutIfNeeded];
CGFloat Width = scrollView.bounds.size.width;
CGFloat Heigh = scrollView.bounds.size.height;
NSLog(@"Width:%f\nHeigh:%f",Width,Heigh);
UIScrollView *scrollView = [[UIScrollView alloc]init];
scrollView.backgroundColor = [UIColor greenColor];
[self.view addSubview:scrollView];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;
self.automaticallyAdjustsScrollViewInsets = NO;
NSString *vflH = @"H:|-10-[scrollView]-10-|";
NSDictionary *views = NSDictionaryOfVariableBindings(scrollView);
NSArray *constraintsH = [NSLayoutConstraint constraintsWithVisualFormat:vflH
options:kNilOptions
metrics:nil
views:views];
[NSLayoutConstraint activateConstraints:constraintsH];
NSString *vflV = @"V:|-74-[scrollView]-10-|";
NSArray *constraintsV = [NSLayoutConstraint constraintsWithVisualFormat:vflV
options:kNilOptions
metrics:nil
views:views];
[NSLayoutConstraint activateConstraints:constraintsV];
[scrollView layoutIfNeeded];
CGFloat Width = scrollView.bounds.size.width;
CGFloat Heigh = scrollView.bounds.size.height;
NSLog(@"Width:%f\nHeigh:%f",Width,Heigh);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询