相关疑难解决方法(0)

如何在Interface Builder中将子视图添加到UIButton

就像我说的,我在Interface Builder中添加了一个UIButton,我想添加一个UILabel,UIImageView作为按钮的子视图,但我不能在IB中添加任何对象.有谁知道怎么做?非常感谢你.

我可以使用代码实现这一点,但我想在IB中实现它,所以我可以在任何我想要的类中使用它.

xcode interface-builder subview uibutton ios

16
推荐指数
2
解决办法
9545
查看次数

将子视图添加到UIButton

我正在尝试添加一个customBadge作为UIButton的子视图 -

到目前为止这是我的代码 -

//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];
Run Code Online (Sandbox Code Playgroud)

我正在尝试添加子视图的按钮是_MsgHeadBtn,这是下面屏幕截图的顶部LH上的电子邮件图标.我试图使自定义徽章在电子邮件图标的上方和右侧略微显示 - 但我最终得到了屏幕截图中的结果!

在此输入图像描述

任何人都可以提出任何关于我哪里出错的建议!?

objective-c uibutton addsubview ios

5
推荐指数
1
解决办法
6636
查看次数