Uon
Uon

Reputation: 23

custom keyboard view frame returning 0

I'm trying to create a button on my custom keyboard. Here's the code I'm currently using:

CGRect ss = [[UIScreen mainScreen] bounds];

self.q = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.q setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[self.q setTitle:@"Q" forState:UIControlStateNormal];
[self.q.titleLabel setTextColor:[UIColor whiteColor]];
self.q.titleLabel.font = [UIFont systemFontOfSize:30];
[self.q setFrame:CGRectMake(0*ss.size.width/10, 0, ss.size.width/10,self.view.bounds.size.height/4)];
[self.q addTarget:self action:@selector(size:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.q];

The problem is that self.view.bounds.size.height seems to be returning 0, when it should be returning the height of the keyboard view. There is a similar question to this, but I have tried the answers and none have worked.

Upvotes: 0

Views: 52

Answers (1)

tuledev
tuledev

Reputation: 10327

You should place these code in viewDidLayoutSubviews.

Ref:https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html

Upvotes: 1

Related Questions