Guest User

Untitled

a guest
Jul 31st, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. How to create UIBarButtonItem with UIImageView and UILabel
  2. UIButton *likecommButton = [UIButton buttonWithType:UIButtonTypeCustom];
  3. likecommButton.backgroundColor = [UIColor clearColor];
  4. [likecommButton addTarget:self action:@selector(likecommButtonClicked:) forControlEvents:UIControlEventTouchDown];
  5.  
  6.  
  7. UIImageView *likeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"like.png"]];
  8. likeImageView.frame = CGRectMake(0.0, 0.0, LikeCommentImageEdge, LikeCommentImageEdge);
  9. likeImageView.backgroundColor = [UIColor clearColor];
  10. [likecommButton addSubview:likeImageView];
  11. [likeImageView release];
  12.  
  13. CGSize numberSize = [@"99" sizeWithFont:[UIFont fontWithName:@"Verdana-Bold" size:12]
  14. constrainedToSize:CGSizeMake(20.0, 20.0)
  15. lineBreakMode:UILineBreakModeTailTruncation];
  16.  
  17. _likeNumberLabel = [[UILabel alloc] initWithFrame: CGRectMake(likeImageView.frame.size.width, 0.0, numberSize.width, numberSize.width)];
  18. _likeNumberLabel.backgroundColor = [UIColor clearColor];
  19. _likeNumberLabel.textColor = [UIColor whiteColor];
  20. _likeNumberLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:12];
  21. _likeNumberLabel.textAlignment = UITextAlignmentRight;
  22. _likeNumberLabel.lineBreakMode = UILineBreakModeClip;
  23. [likecommButton addSubview:_likeNumberLabel];
  24.  
  25. UIImageView *commentImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment.png"]];
  26. commentImageView.frame = CGRectMake(_likeNumberLabel.frame.origin.x + _likeNumberLabel.frame.size.width, 0.0, LikeCommentImageEdge, LikeCommentImageEdge);
  27. commentImageView.backgroundColor = [UIColor clearColor];
  28. [likecommButton addSubview:commentImageView];
  29. [commentImageView release];
  30.  
  31. _commentNumberLabel = [[UILabel alloc] initWithFrame: CGRectMake(toolBarButtonWidth - numberSize.width, 0.0, numberSize.width, numberSize.width)];
  32. _commentNumberLabel.backgroundColor = [UIColor clearColor];
  33. _commentNumberLabel.textColor = [UIColor whiteColor];
  34. _commentNumberLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:12];
  35. _commentNumberLabel.textAlignment = UITextAlignmentRight;
  36. _commentNumberLabel.lineBreakMode = UILineBreakModeClip;
  37. [likecommButton addSubview:_commentNumberLabel];
  38.  
  39. likecommButton.frame = CGRectMake(0.0, 0.0, toolBarButtonWidth, numberSize.height);
  40.  
  41. _likeCommCountButton = [[UIBarButtonItem alloc] initWithCustomView:likecommButton];
  42. _likeCommCountButton.width = toolBarButtonWidth;
  43. _likeCommCountButton.enabled = NO;
  44.  
  45. segmentControl.tintColor = [UIColor clearColor];
  46. segmentControl.backgroundColor = [UIColor clearColor];
  47.  
  48. UIView *BtnView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,35)];
  49. UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
  50. [myButton setFrame:CGRectMake(0,3,70,32)];
  51. [myButton setImage:[UIImage imageNamed:@"firstImage.png"] forState:UIControlStateNormal];
  52. [myButton addTarget:self action:@selector(compete) forControlEvents:UIControlEventTouchUpInside];
  53.  
  54.  
  55.  
  56. UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(52, -4, 21, 21)];
  57. [imageView setImage:[UIImage imageNamed:@"Secongimage.png"]];
  58. UILabel *badge_Label=[[UILabel alloc]initWithFrame:CGRectMake(5,3, 15, 15)];
  59. badge_Label.backgroundColor=[UIColor clearColor];
  60. badge_Label.font=[UIFont systemFontOfSize:12];
  61. [badge_Label setText:@"20"];
  62. [imageView addSubview:badge_Label];
  63.  
  64.  
  65. [BtnView addSubview:myButton];
  66. [BtnView addSubview:imageView];
  67. [myButton release];
  68.  
  69. UIBarButtonItem *CompeteButton = [[UIBarButtonItem alloc]initWithCustomView:BtnView];
  70.  
  71. self.navigationItem.rightBarButtonItem = CompeteButton;
  72.  
  73.  
  74. UIView *leftBtnView = [[UIView alloc] initWithFrame:CGRectMake(0,0,40,40)];
  75. UIButton *menu_Button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
  76. [menu_Button setFrame:CGRectMake(0,3,37,37)];
  77. [menu_Button setImage:[UIImage imageNamed:@"menubut.png"] forState:UIControlStateNormal];
  78. [menu_Button addTarget:self action:@selector(list) forControlEvents:UIControlEventTouchUpInside];
  79.  
  80. [leftBtnView addSubview:menu_Button];
  81.  
  82. UIBarButtonItem *menuButton = [[UIBarButtonItem alloc]initWithCustomView:leftBtnView];
  83. self.navigationItem.leftBarButtonItem = menuButton;
Advertisement
Add Comment
Please, Sign In to add comment