배지가있는 버튼을 만드는 편리한 방법이 있습니까? 아이콘에 없으면 ... 앱 안에서 해보고 싶습니다. 프로그램에서 선택한 배지가있는 단추 또는 이미지. 아니면 포토샵 이미지 라이브러리를 만들어야합니까?둥근 버튼에 배지 아이콘을 추가 하시겠습니까?
3
A
답변
3
포토샵 이미지 라이브러리없이이 작업을 수행하려면 resizableImageWithCapInsets
을 사용해야합니다. 그 사용법을 설명하는 위대한 스레드 (here 및 here)가 있습니다.
//Create a label (width/height not important at this stage)
UILabel *yourLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 1, 1)];
yourLabel.text = @"7+";
[yourLabel sizeToFit];
CGRect labelFrame = yourLabel.frame;
//Here we create a UIImage that is resizable, but will not resize the areas concerned with the cap insets you've defined
UIImage *badgeImage = [[UIImage imageNamed:@"badge.png"]resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
UIImageView *badgeImageView = [[UIImageView alloc]initWithImage:badgeImage];
badgeImageView.contentMode = UIViewContentModeScaleToFill;
badgeImageView.backgroundColor = [UIColor clearColor];
labelFrame.size.width += 5; //This is the 'padding' on the right and left (added together)
//If your badge edges are completely circular then you don't want to change the height, but if they're not then go ahead in the same way with the width. If your badge has a static height, you'll need to make sure the font size doesn't exceed this height; better start off with a small font-size
badgeImageView.frame = labelFrame; //The badge is now the right width with padding taken into account
//Center the label on the badge image view
yourLabel.center = CGPointMake(badgeImageView.frame.size.width/2, badgeImageView.frame.size.height/2);
//Finally we add the label to the badge image view
[badgeImageView addSubview:yourLabel];
//Add your badge to the main view
[self.view addSubview:badgeImageView];
[badgeImageView release];
[yourLabel release];
+0
정말 고마워요. 나는 그것을 시도 할 것입니다. –
0
UILabel *lbl_notification_count = [[UILabel alloc]initWithFrame:CGRectMake(5,0, 18, 18)];
lbl_notification_count.textColor = [UIColor whiteColor];
lbl_notification_count.textAlignment = NSTextAlignmentCenter;
lbl_notification_count.text = [NSString stringWithFormat:@"%d",appDel.NotificationBadge];
lbl_notification_count.adjustsFontSizeToFitWidth=YES;
lbl_notification_count.layer.borderWidth = 1;
lbl_notification_count.layer.cornerRadius = lbl_notification_count.layer.frame.size.height/2;
lbl_notification_count.layer.masksToBounds = YES;
lbl_notification_count.layer.borderColor =[[UIColor colorWithRed:241.0/255.0 green:84.0/255.0 blue:67.0/255.0 alpha:1.0] CGColor];
lbl_notification_count.backgroundColor = [UIColor colorWithRed:241.0/255.0 green:84.0/255.0 blue:67.0/255.0 alpha:1.0];
lbl_notification_count.font = CustomFontMediumWithSize(12);
if (appDel.NotificationBadge >= 1) {
[btnNotification addSubview:lbl_notification_count];
[lbl_notification_count setHidden:NO];
}else{
[lbl_notification_count setHidden:YES];
}
관련 문제
- 1. 버튼에 이미지 아이콘을 추가 하시겠습니까?
- 2. jquery가있는 버튼에 아이콘을 추가 할 때의 문제
- 3. Blackberry - 이미지를 버튼에 추가 하시겠습니까?
- 4. 버튼에 아이콘을 추가하는 방법
- 5. p : 패널에 아이콘을 추가 하시겠습니까?
- 6. jQuery 버튼에 아이콘 추가
- 7. Trello에 배지 추가
- 8. iOS - UITableViewCell에 배지 추가
- 9. 버튼에 진행 아이콘을 표시하려면 어떻게해야합니까?
- 10. 하나의 버튼에 두 개의 애니메이션을 추가 하시겠습니까?
- 11. Windows.Forms 종료 버튼에 기능을 추가 하시겠습니까?
- 12. 응용 프로그램에만 시스템 트레이 아이콘을 추가 하시겠습니까?
- 13. 둥근 버튼에 대해 사과가 지원하는 색상
- 14. Magento에 Google 신뢰 배지 추가
- 15. 배지, 아이템 번호를 업데이트 하시겠습니까?
- 16. 아이콘을 강조 버튼에 배치하는 방법은 무엇입니까?
- 17. jQuery를 사용하여 버튼에 기본 아이콘을 설정하는 방법
- 18. 특정 버튼에 이미지 아이콘을 추가하는 방법은 무엇입니까?
- 19. 버튼에 활성 상태 추가
- 20. 버튼에 애니메이션 추가
- 21. 버튼에 설명 추가
- 22. 버튼에 행 추가
- 23. 뒤로 버튼에 작업 추가
- 24. 버튼에 클릭 노이즈 추가
- 25. 버튼에 이미지 추가
- 26. 버튼에 기능 추가
- 27. NSRunAlertPanel의 버튼에 액션 추가
- 28. 버튼에 이미지 추가
- 29. 배지 시스템 및 조건을 변수로 저장 하시겠습니까?
- 30. 오버레이 아이콘을 구현 하시겠습니까?
자동으로 텍스트의 폭을 조정하는 배지를 의미 : 여기
난 그냥 당신에게 아이디어를 제공하기 위해 만든 예입니다? – sooper