【问题标题】:How to add Button Style by using buttonWithType in Objective-C?如何在 Objective-C 中使用 buttonWithType 添加按钮样式?
【发布时间】:2014-09-29 03:17:18
【问题描述】:

我在故事板中添加了如下图所示的按钮:

我在头文件中也添加了代码,如下代码所示:

#import <UIKit/UIKit.h>

    @interface ViewController : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate>

    @property (strong, nonatomic) IBOutlet UIButton *Up;
    @property (strong, nonatomic) IBOutlet UIButton *Back;
    @property (strong, nonatomic) IBOutlet UIButton *Left;
    @property (strong, nonatomic) IBOutlet UIButton *Ok;
    @property (strong, nonatomic) IBOutlet UIButton *Right;
    @property (strong, nonatomic) IBOutlet UIPickerView *DeviceSelect;

    @end

我想在.m文件中添加UIButton的样式,如下代码所示:

self.Up = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.view addSubview:_Up];

但它似乎不起作用。 UIButton 没有改变任何东西。

我错过了什么吗?

我是 iOS 新手,请教我...提前谢谢。

【问题讨论】:

标签: ios objective-c uibutton


【解决方案1】:

您已经在情节提要文件中添加了按钮,并且因为您以这种方式添加了按钮,所以您不应该执行以下两行代码:

self.Up = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.view addSubview:_Up];

您可以通过 Xcode 的 Interface Builder 中的属性检查器(在编辑故事板时看到)设置按钮样式。

看起来像这样:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-26
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 2020-08-11
    • 2011-01-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多