我只是想輕鬆打印出myButton維度。請檢查代碼:UIButton的邊界和框架
@interface ViewController : UIViewController
@property (nonatomic, strong) IBOutlet UIButton *myButton;
和.m文件:
@implementation ViewController
@synthesize myButton;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGRect f2 = self.myButton.bounds;
printf("x: %f\n", f2.origin.x);
CGSize f3 = self.myButton.frame.size;
printf("x: %f\n", f3.height);
}
- (void)viewWillAppear:(BOOL)animated {
CGRect f2 = self.myButton.bounds;
printf("x: %f\n", f2.origin.x);
CGSize f3 = self.myButton.bounds.size;
printf("x: %f\n", f3.height);
}
這是我在控制檯收到:
x: 0.000000
x: 0.000000
x: 0.000000
x: 0.000000
你能不能幫我,我怎麼能打印呢?
是你積極的,你已經連接IBOutlet到UIButton在xib – AppleDelegate
是的,我做了,我非常確定。 – Ali
試試這個NSLog(@「Button Frame - %@」,[myButton description]);在這個檢查你的框架(或)NSLog(@「Button Frame - %@」,[myButton.frame]); –