- How to create UIBarButtonItem with UIImageView and UILabel
- UIButton *likecommButton = [UIButton buttonWithType:UIButtonTypeCustom];
- likecommButton.backgroundColor = [UIColor clearColor];
- [likecommButton addTarget:self action:@selector(likecommButtonClicked:) forControlEvents:UIControlEventTouchDown];
- UIImageView *likeImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"like.png"]];
- likeImageView.frame = CGRectMake(0.0, 0.0, LikeCommentImageEdge, LikeCommentImageEdge);
- likeImageView.backgroundColor = [UIColor clearColor];
- [likecommButton addSubview:likeImageView];
- [likeImageView release];
- CGSize numberSize = [@"99" sizeWithFont:[UIFont fontWithName:@"Verdana-Bold" size:12]
- constrainedToSize:CGSizeMake(20.0, 20.0)
- lineBreakMode:UILineBreakModeTailTruncation];
- _likeNumberLabel = [[UILabel alloc] initWithFrame: CGRectMake(likeImageView.frame.size.width, 0.0, numberSize.width, numberSize.width)];
- _likeNumberLabel.backgroundColor = [UIColor clearColor];
- _likeNumberLabel.textColor = [UIColor whiteColor];
- _likeNumberLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:12];
- _likeNumberLabel.textAlignment = UITextAlignmentRight;
- _likeNumberLabel.lineBreakMode = UILineBreakModeClip;
- [likecommButton addSubview:_likeNumberLabel];
- UIImageView *commentImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"comment.png"]];
- commentImageView.frame = CGRectMake(_likeNumberLabel.frame.origin.x + _likeNumberLabel.frame.size.width, 0.0, LikeCommentImageEdge, LikeCommentImageEdge);
- commentImageView.backgroundColor = [UIColor clearColor];
- [likecommButton addSubview:commentImageView];
- [commentImageView release];
- _commentNumberLabel = [[UILabel alloc] initWithFrame: CGRectMake(toolBarButtonWidth - numberSize.width, 0.0, numberSize.width, numberSize.width)];
- _commentNumberLabel.backgroundColor = [UIColor clearColor];
- _commentNumberLabel.textColor = [UIColor whiteColor];
- _commentNumberLabel.font = [UIFont fontWithName:@"Verdana-Bold" size:12];
- _commentNumberLabel.textAlignment = UITextAlignmentRight;
- _commentNumberLabel.lineBreakMode = UILineBreakModeClip;
- [likecommButton addSubview:_commentNumberLabel];
- likecommButton.frame = CGRectMake(0.0, 0.0, toolBarButtonWidth, numberSize.height);
- _likeCommCountButton = [[UIBarButtonItem alloc] initWithCustomView:likecommButton];
- _likeCommCountButton.width = toolBarButtonWidth;
- _likeCommCountButton.enabled = NO;
- segmentControl.tintColor = [UIColor clearColor];
- segmentControl.backgroundColor = [UIColor clearColor];
- UIView *BtnView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,35)];
- UIButton *myButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
- [myButton setFrame:CGRectMake(0,3,70,32)];
- [myButton setImage:[UIImage imageNamed:@"firstImage.png"] forState:UIControlStateNormal];
- [myButton addTarget:self action:@selector(compete) forControlEvents:UIControlEventTouchUpInside];
- UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(52, -4, 21, 21)];
- [imageView setImage:[UIImage imageNamed:@"Secongimage.png"]];
- UILabel *badge_Label=[[UILabel alloc]initWithFrame:CGRectMake(5,3, 15, 15)];
- badge_Label.backgroundColor=[UIColor clearColor];
- badge_Label.font=[UIFont systemFontOfSize:12];
- [badge_Label setText:@"20"];
- [imageView addSubview:badge_Label];
- [BtnView addSubview:myButton];
- [BtnView addSubview:imageView];
- [myButton release];
- UIBarButtonItem *CompeteButton = [[UIBarButtonItem alloc]initWithCustomView:BtnView];
- self.navigationItem.rightBarButtonItem = CompeteButton;
- UIView *leftBtnView = [[UIView alloc] initWithFrame:CGRectMake(0,0,40,40)];
- UIButton *menu_Button = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
- [menu_Button setFrame:CGRectMake(0,3,37,37)];
- [menu_Button setImage:[UIImage imageNamed:@"menubut.png"] forState:UIControlStateNormal];
- [menu_Button addTarget:self action:@selector(list) forControlEvents:UIControlEventTouchUpInside];
- [leftBtnView addSubview:menu_Button];
- UIBarButtonItem *menuButton = [[UIBarButtonItem alloc]initWithCustomView:leftBtnView];
- self.navigationItem.leftBarButtonItem = menuButton;