Wun
Wun

Reputation: 6381

How to add Button Style by using buttonWithType in Objective-C?

I have added the button in storyboard like the following picture:

enter image description here

I also have added the code in the header file as shown in the following code:

#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

I want to add the style for the UIButton in the .m file as shown in the following code:

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

But it seems its not working. The UIButton didn't change anything.

Did I miss something?

I am new to iOS , Please teach me... Thanks in advance.

Upvotes: 1

Views: 1589

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89519

You've already added your button in the storyboard file and because you added buttons that way, you should not do these two lines of code:

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

You can set the button style via the attributes inspector in Xcode's Interface Builder (which you see when editing the storyboard).

It looks like this:

Use Attributes Inspector to set the button type

Upvotes: 1

Related Questions