Guest User

Untitled

a guest
Oct 23rd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
  2. [myButton setBackgroundColor:[UIColor blackColor]];
  3. [myButton setAlpha:0.7];
  4. [myButton setTitle:@"Hello" forState:UIControlStateNormal];
  5. [myButton addTarget:self action:@selector(userClicked:) forControlEvents:UIControlEventTouchUpInside];
  6.  
  7. [parentView addSubview:myButton];
  8.  
  9. -(void) userClicked:(UIButton*)button
  10. {
  11. NSLog(@"USER CLICKED!!!");
  12. if ([NSThread isMainThread])
  13. {
  14. NSLog(@"is main thread");
  15. }
  16.  
  17. [button setTitle:@"Bye" forState:UIControlStateHighlighted];
  18. [button setTitle:@"Bye" forState:UIControlStateNormal];
  19. [button setTitle:@"Bye" forState:UIControlStateSelected];
  20.  
  21. [self someLengthyComputation];
  22. }
  23.  
  24. USER CLICKED!!!
  25. isMainThread
  26.  
  27. Printing description of button->_titleView:
  28. <UIButtonLabel: 0xa4c9310; frame = (95 216; 130 22); text = 'Bye'; clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0xa44f080>>
  29.  
  30. button.enabled = FALSE;
  31. [button setTitle:@"Test" forState:UIControlStateNormal];
  32. button.enabled = TRUE;
  33.  
  34. [button setAttributedTitle:@"" forState:UIControlStateNormal];
  35.  
  36. [button setTitle:@"" forState:UIControlStateNormal];
  37.  
  38. [button setNeedsLayout];
  39.  
  40. [mybutton setTitle:@"SomeText" forState:UIControlStateNormal];
  41. [button setNeedsLayout];
  42. [button layoutIfNeeded];
  43.  
  44. -(IBAction)changeButtonText:(id)sender {
  45. if (!buttonToggled) {
  46. [sender setTitle:@"Initial Text" forState:UIControlStateNormal];
  47. buttonToggled = YES;
  48. } else {
  49. [sender setTitle:@"Alternative Text" forState:UIControlStateNormal];
  50. buttonToggled = NO;
  51. }
  52. }
  53.  
  54. @selector(userClicked:)
  55.  
  56. -(void)userTapOnTapToRefreshView:(UIButton*)button
  57.  
  58. -(void)userClicked:(id)sender
  59. {
  60. [(UIButton*)sender setTitle:@"Bye" forState:UIControlStateNormal];
  61. }
  62.  
  63. [parentView myButton];
  64.  
  65. [parentView addSubview:myButton];
  66.  
  67. [button setTitle:title forState:UIControlStateNormal];
  68. [button setTitle:title forState:UIControlStateDisabled];
  69.  
  70. [button setTitle:@"Bye" forState:UIControlStateHighlighted];
  71.  
  72. [button setTitle:@"Bye" forState:UIControlStateSelected];
  73.  
  74. -(void) userClicked
  75. {
  76. NSLog(@"USER CLICKED!!!");
  77. if ([NSThread isMainThread])
  78. {
  79. NSLog(@"is main thread");
  80. }
  81.  
  82. [myButton setTitle:@"Bye" forState:UIControlStateNormal];
  83. }
  84.  
  85. [button setNeedsLayout];
  86. [button layoutIfNeeded];
  87.  
  88. -(void) userClicked:(UIButton*)button
  89. {
  90. NSLog(@"USER CLICKED!!!");
  91. if ([NSThread isMainThread])
  92. {
  93. NSLog(@"is main thread");
  94. }
  95.  
  96. [button setTitle:@"Bye" forState:UIControlStateHighlighted];
  97. [button setTitle:@"Bye" forState:UIControlStateNormal];
  98. [button setTitle:@"Bye" forState:UIControlStateSelected];
  99. dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
  100. [self someLengthyComputation];
  101. });
  102. }
  103.  
  104. [myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  105.  
  106. [myButton setTitle:@"SomeText" forState:UIControlStateNormal];.
  107.  
  108. button.setTitle("My title", for: .normal)
  109.  
  110. button.setAttributedTitle(<AttributedString>, for: .normal)
  111.  
  112. NSMutableAttributedString *attString = [[NSMutableAttributedString alloc] initWithString:@" new Test "];
  113.  
  114. [button setAttributedTitle:attString forState:UIControlStateNormal];
  115.  
  116. [button setNeedsLayout];
  117. [button layoutIfNeeded];
  118.  
  119. [button setAttributedTitle:[NSAttributedString new] forState:UIControlStateNormal];
  120.  
  121. [button setTitleColor:[any_color] forState:UIControlStateNormal];
  122.  
  123. @property(nonatomic,strong) UIButton* myButton;
  124.  
  125. self.myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
  126. [_myButton setBackgroundColor:[UIColor blackColor]];
  127. ...
  128.  
  129. @implementation myViewController
  130. {
  131. UIButton* myButton;
  132. }
  133.  
  134. -(void)createButton
  135. {
  136. myButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, parentView.frame.size.width, parentView.frame.size.height)];
  137. [myButton setBackgroundColor:[UIColor blackColor]];
  138. ...
  139. }
  140.  
  141. ...
Add Comment
Please, Sign In to add comment