Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. @implementation ViewController
  2. @synthesize name = _name ;
  3. - (void)viewDidLoad
  4. {
  5. [super viewDidLoad];
  6. int y = 20 ;
  7. for(int i=1; i <= 10; i++)
  8. {
  9. CGRect frame = CGRectMake(20, y, 100, 30 ) ;
  10. name = [[UITextField alloc] initWithFrame:frame];
  11. [name setTag:i] ;
  12. [name setBackgroundColor:[UIColor whiteColor]] ;
  13. [name addTarget:self action:@selector(makeBlue:) forControlEvents:UIControlEventTouchDown];
  14. [self.view addSubview:name];
  15. y += 38;
  16. }
  17. }
  18.  
  19. - (void)makeBlue:(id)sender
  20. {
  21. int i = (int)[sender tag] ;
  22. [name setTag:i] ;
  23. NSLog(@"%d", i);
  24. [name setBackgroundColor:[UIColor blueColor]] ;
  25. }
  26.  
  27. - (void)viewDidLoad
  28. {
  29. [super viewDidLoad];
  30.  
  31. int y = 20 ;
  32. for(int tag=1; tag <= 10; tag++)
  33. {
  34. CGRect frame = CGRectMake(20, y, 100, 30 ) ;
  35. name = [[UITextField alloc] initWithFrame:frame];
  36. [name setTag:tag] ;
  37. [name setBackgroundColor:[UIColor whiteColor]] ;
  38. [name addTarget:self action:@selector(makeItSo:) forControlEvents:UIControlEventEditingDidEnd];
  39. [self.view addSubview:name];
  40. [name setDelegate:self] ;
  41. y += 38;
  42. }
  43. }
  44.  
  45. - (void)makeItSo:(id)sender
  46. {
  47. int tag = (int)[sender tag] ;
  48. [name setTag:tag] ;
  49. NSString * aName = [name text] ;
  50. NSLog(@"%@", aName) ;
  51. }
  52.  
  53. [self.view viewWithTag:<tag>]
  54.  
  55. - (void)makeBlue:(id)sender
  56. {
  57. int tag = (int)[sender tag] ;
  58. UIView *tagView = [self.view viewWithTag:tag]
  59. [tagView setBackgroundColor:[UIColor blueColor]] ;
  60. }
  61.  
  62. name = [self.view viewWithTag:[sender tag]];
  63. NSString *fieldText = name.text;
  64.  
  65. NSInteger i = [sender tag];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement