5

UIButton のサブビューとして customBadge を追加しようとしています -

これはこれまでの私のコードです-

//msg count initiaition
//CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"];
CustomBadge *customBadge1 = [CustomBadge customBadgeWithString:@"2"
                                               withStringColor:[UIColor whiteColor]
                                                withInsetColor:[UIColor redColor]
                                                withBadgeFrame:YES
                                           withBadgeFrameColor:[UIColor redColor]
                                                     withScale:2.0
                                                   withShining:YES];

    // Set Position of Badge 1
[customBadge1 setFrame:CGRectMake(self.view.frame.size.width/2-customBadge1.frame.size.width/2+_MsgHeadBtn.frame.size.width/2, 110, customBadge1.frame.size.width, customBadge1.frame.size.height)];
 //add badge to view
[_MsgHeadBtn addSubview:customBadge1];

サブビューを追加しようとしているボタンは _MsgHeadBtn です。これは、下のスクリーンショットの上部 LH にある電子メール アイコンです。カスタムバッジをメールアイコンの少し上と右に表示しようとしていましたが、結果はスクリーンショットになりました!

ここに画像の説明を入力

どこが間違っているのか、誰かアドバイスをいただけますか!?

4

2 に答える 2

5

問題はあなたのsetFrame:方法の中にあります。を使用してself.view.frame.size.widthいます。

このコードで確認してください:

[customBadge1 setCenter:CGPointMake(_MsgHeadBtn.frame.size.width, 0)];
[_MsgHeadBtn addSubview:customBadge1];

また

[customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width, 0, customBadge1.frame.size.width, customBadge1.frame.size.height)];
[_MsgHeadBtn addSubview:customBadge1];
于 2013-10-31T11:08:33.560 に答える
1

以下のようにフレームを調整します。

[customBadge1 setFrame:CGRectMake(_MsgHeadBtn.frame.size.width-customBadge1.frame.size.width,-customBadge1.frame.size.height/2, customBadge1.frame.size.width, customBadge1.frame.size.height)];
于 2013-10-31T11:13:12.680 に答える