バッジ付きのボタンを作成する便利な方法はありますか?アイコンではない...私はアプリ内でそれをやりたいプログラムによって選択されたバッジ付きのボタンまたは画像。または、Photoshopイメージのライブラリを構築する必要がありますか?ラウンドレットボタンにバッジアイコンを追加しますか?
3
A
答えて
3
これを実現するには、Photoshopイメージライブラリなしで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. alt値を動的に追加/追加しますか?
- 3. UIScrollViewにUIButtonを追加し、UIScrollViewをUIViewに追加します。
- 4. 条件を追加し、pandasデータフレームを追加しますか?
- 5. ウェブページにperlを追加しますか?
- 6. プラグインをejsに追加しますか?
- 7. MKOverlayRendererにCALayerを追加しますか?
- 8. SlickGridにカスタムボタンを追加しますか?
- 9. イベントをクラスメソッドに追加しますか?
- 10. カスタムスクリプトをScriptManagerに追加しますか?
- 11. jQuery.ajaxにdataTypesを追加しますか?
- 12. ページカールアニメーションをNSViewに追加しますか?
- 13. "this"をイベントリスナーに追加しますか?
- 14. ジェスチャービルダーをアプリに追加しますか?
- 15. コアテキストにハイフネーションを追加しますか?
- 16. .htaccessをキャッシュマニフェストに追加しますか?
- 17. DynamicResourceにスペースを追加しますか?
- 18. アンドロイドスタジオプロジェクトにライブラリを追加しますか?
- 19. req.validationErrors()にカスタムエラーを追加しますか?
- 20. オペレータをサードパーティタイプに追加しますか?
- 21. ドロップダウンボックスにオプションを追加しますか?
- 22. iframeにjavascriptを追加しますか?
- 23. ドメインサービスクラスにイベントを追加しますか?
- 24. イメージをブートストラップに追加しますか?
- 25. スライドスクリプトにフェードを追加しますか?
- 26. CCSpriteにUIImageを追加しますか?
- 27. ウェブビューにコンテンツを追加しますか?
- 28. Alternativa3dにテキストを追加しますか?
- 29. スクロールバーをJListに追加しますか?
- 30. VB.netにキーワードを追加しますか?
あなたは自動的にあなたのテキストの幅に調整されます。バッジを意味ですか? – sooper