获取控件的宽和高

iOS 码拜 9年前 (2015-05-03) 778次浏览 0个评论
 

怎么获取文本框或者按钮的宽和高?
麻烦各位给段代码。。。

获取控件的宽和高
这里的人这么少么?

获取控件的宽和高
20分
这个版块的人真的少啊,我来回答你吧.
UIButton *button;//(加入有这个button)
int width = button.frame.size.width;
int height = button.frame.size.height;
获取控件的宽和高
ls正解
获取控件的宽和高
像我这种初学者还是蛮多的。。。呵呵。。。学习了
获取控件的宽和高
建议这样写吧
for(UIView * view in [self.view.superView subviews]){
    if([view isKindOfClass:[UIButton  class]]) // 这里输入你想获取的控件的类
    {
        int width = view.frame.size.width;
        int height = view.frame.size.height;
    }
}
希望可以帮到你。
获取控件的宽和高
引用 2 楼 fushaobing 的回复:

这个版块的人真的少啊,我来回答你吧.
UIButton *button;//(加入有这个button)
int width = button.frame.size.width;
int height = button.frame.size.height;

获取控件的宽和高
建议封装成分类

@interface UIView(helper)

– (CGFloat)width;
– (CGFloat)height;

@end

@implementation UIView(helper)

– (CGFloat)width
{
  return self.frame.size.width;
}

– (CGFloat)height
{
  return self.frame.size.height;
}

@end

这么用多方便


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明获取控件的宽和高
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!