Reputation: 451
I'm new to Objective C. I have the following code :
UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(25, self.view.bounds.size.height-60, 230, 45)];
loginButton.backgroundColor =UIColorFromAltRGB(0xa40002);//RGB4(0xa40002);
loginButton.layer.cornerRadius = 5.0f;
loginButton.titleLabel.font = [UIFont fontWithName:boldFontName size:14.0f];
[loginButton setTitle:@"CREATE" forState:UIControlStateNormal];
[loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[loginButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateHighlighted];
[loginButton addTarget:self action:@selector(createUser) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:loginButton];
whit :
-(void)createUser
{
NSLog(@"create");
(....)
}
But it never show/log. Not entering the createuser.
LE :
if i put
NSLog(@"he did load : %@",self.delegate);
it shows me the first screen. It suppose to show me the current viewcontroller ?
LE :
i resolve the problem by setting :
self.delegate = self
don't know why is working now... but it's ok... not my code Thanks all for help
Upvotes: 0
Views: 120
Reputation: 56
change bound to frame, then you can console the create user
UIButton *loginButton = [[UIButton alloc] initWithFrame:CGRectMake(25, self.view.frame.size.height-60, 230, 45)];
loginButton.backgroundColor =UIColorFromAltRGB(0xa40002);//RGB4(0xa40002);
loginButton.layer.cornerRadius = 5.0f;
loginButton.titleLabel.font = [UIFont fontWithName:boldFontName size:14.0f];
[loginButton setTitle:@"CREATE" forState:UIControlStateNormal];
[loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[loginButton setTitleColor:[UIColor colorWithWhite:1.0f alpha:0.5f] forState:UIControlStateHighlighted];
[loginButton addTarget:self action:@selector(createUser) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:loginButton];
Upvotes: 0
Reputation: 691
Your code is working for me too. Another option is to verify you don't have a custom gesture recogniser attached to the entire view or its superview, if so, set this property in your gesture recogniser:
gesture.cancelsTouchesInView = NO;
Upvotes: 0
Reputation: 3067
Your code works, I just verified it myself. Check that self.view
's frame is well configured. If it doesn't cover at the very least loginButton.frame
then it won't be clickable.
Upvotes: 1