hachinoBlog

hachinobuのエンジニアライフ

UIViewに枠線や枠の色および角丸を設定する方法

UIViewやUIButtonなどに枠線をつけたりする方法を忘れて毎回ぐぐっているのでメモ。

f:id:hachinobu:20140120165637p:plain

やり方

    UIView *layerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
    layerView.center = self.view.center;
    //枠線
    layerView.layer.borderWidth = 2.0f;
    //枠線の色
    layerView.layer.borderColor = [[UIColor redColor] CGColor];
    //角丸
    layerView.layer.cornerRadius = 10.0f;

必ず<QuartzCore/QuartzCore.h>をインポートすること。

以上。