7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

UIButton境界線だしつつStoryboardで設計

Posted at

 iOS7にかわってから、UIButtonの境界線がなくなりました。Storyboardは画面遷移が可視化できるため非常に便利です。ここで問題はStoryboardを使いながらUIButtonの境界線を出す方法です。

 UIButtonの境界線を出す方法はButtonをIBOutletで定義する必要があります。

ViewController.m
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *button;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    _button.layer.borderColor = [UIColor grayColor].CGColor;
    _button.layer.borderWidth = 1.0f;
    _button.layer.cornerRadius = 7.5f;
}

このような感じで境界線を出します。
次に画面遷移を個別に定義します。

ViewController.m
   [_button addTarget:self action:@selector(done) forControlEvents:UIControlEventTouchDown];

 このような感じです。次にdoneを記述して画面遷移を記述します。ここで忘れていけないことはStoryboard上でStoryboard IDに何かKeyword指定です。ここではSecondViewControllerとしておきます。
 次にdoneを記述します。

ViewController.m
- (void)done{
    SecondViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    [self.navigationController pushViewController:vc animated:YES];
}

これでButtonをカスタマイズしつつStoryboardでUI設計できます。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?