Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
- [myButton setBackgroundColor:[UIColor blackColor]];
- [myButton setAlpha:0.7];
- [myButton setTitle:@"Hello" forState:UIControlStateNormal];
- [myButton addTarget:self action:@selector(userClicked:) forControlEvents:UIControlEventTouchUpInside];
- [parentView addSubview:myButton];
- -(void) userClicked:(UIButton*)button
- {
- NSLog(@"USER CLICKED!!!");
- if ([NSThread isMainThread])
- {
- NSLog(@"is main thread");
- }
- [button setTitle:@"Bye" forState:UIControlStateHighlighted];
- [button setTitle:@"Bye" forState:UIControlStateNormal];
- [button setTitle:@"Bye" forState:UIControlStateSelected];
- [self someLengthyComputation];
- }
- USER CLICKED!!!
- isMainThread
- Printing description of button->_titleView:
- <UIButtonLabel: 0xa4c9310; frame = (95 216; 130 22); text = 'Bye'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa44f080>>
- button.enabled = FALSE;
- [button setTitle:@"Test" forState:UIControlStateNormal];
- button.enabled = TRUE;
- [button setAttributedTitle:@"" forState:UIControlStateNormal];
- [button setTitle:@"" forState:UIControlStateNormal];
- [button setNeedsLayout];
- [mybutton setTitle:@"SomeText" forState:UIControlStateNormal];
- [button setNeedsLayout];
- [button layoutIfNeeded];
- -(IBAction)changeButtonText:(id)sender {
- if (!buttonToggled) {
- [sender setTitle:@"Initial Text" forState:UIControlStateNormal];
- buttonToggled = YES;
- } else {
- [sender setTitle:@"Alternative Text" forState:UIControlStateNormal];
- buttonToggled = NO;
- }
- }
- @selector(userClicked:)
- -(void)userTapOnTapToRefreshView:(UIButton*)button
- -(void)userClicked:(id)sender
- {
- [(UIButton*)sender setTitle:@"Bye" forState:UIControlStateNormal];
- }
- [parentView myButton];
- [parentView addSubview:myButton];
- [button setTitle:title forState:UIControlStateNormal];
- [button setTitle:title forState:UIControlStateDisabled];
- [button setTitle:@"Bye" forState:UIControlStateHighlighted];
- [button setTitle:@"Bye" forState:UIControlStateSelected];
- -(void) userClicked
- {
- NSLog(@"USER CLICKED!!!");
- if ([NSThread isMainThread])
- {
- NSLog(@"is main thread");
- }
- [myButton setTitle:@"Bye" forState:UIControlStateNormal];
- }
- [button setNeedsLayout];
- [button layoutIfNeeded];
- -(void) userClicked:(UIButton*)button
- {
- NSLog(@"USER CLICKED!!!");
- if ([NSThread isMainThread])
- {
- NSLog(@"is main thread");
- }
- [button setTitle:@"Bye" forState:UIControlStateHighlighted];
- [button setTitle:@"Bye" forState:UIControlStateNormal];
- [button setTitle:@"Bye" forState:UIControlStateSelected];
- dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
- [self someLengthyComputation];
- });
- }
- [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- [myButton setTitle:@"SomeText" forState:UIControlStateNormal];.
- button.setTitle("My title", for: .normal)
- button.setAttributedTitle(<AttributedString>, for: .normal)
- NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@" new Test "];
- [button setAttributedTitle:attString forState:UIControlStateNormal];
- [button setNeedsLayout];
- [button layoutIfNeeded];
- [button setAttributedTitle:[NSAttributedString new] forState:UIControlStateNormal];
- [button setTitleColor:[any_color] forState:UIControlStateNormal];
- @property(nonatomic,strong) UIButton* myButton;
- self.myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
- [_myButton setBackgroundColor:[UIColor blackColor]];
- ...
- @implementation myViewController
- {
- UIButton* myButton;
- }
- -(void)createButton
- {
- myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
- [myButton setBackgroundColor:[UIColor blackColor]];
- ...
- }
- ...
Add Comment
Please, Sign In to add comment