UIView

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
枠描画
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
CALayer *layer = self.view.layer;
layer.borderWidth = 1.0f;
layer.borderColor = [[UIColor lightGrayColor] CGColor];
layer.cornerRadius = 2.0f;

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
影を付ける
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
CALayer *layer = self.view.layer;
layer.borderWidth = 1.0f;
layer.borderColor = [[UIColor lightGrayColor] CGColor];
layer.cornerRadius = 2.0f;
layer.shadowOpacity = 0.6f;
layer.shadowOffset = CGSizeMake(1.0f, 1.0f);

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
サブビューを移動する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

[self.view bringSubviewToFront:frontView]; // frontView を最前面に移動
[self.view sendSubviewToBack:backView] // backView を最背面に移動

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
サブビューを挿入する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
既存subview2の上に新たにsubview1が挿入される
[parentView insertSubview:subview1 aboveSubview:subview2];

既存subview2の下に新たにsubview1が挿入される
[parentView insertSubview:subview1 belowSubview:subview2];

parentViewのサブビューリストのindexの位置に新たにsubview1を挿入する
[parentView insertSubview:subview1 atIndex:index];

// したがって、以下は、イコールとなる。
[parentView insertSubview:subview atIndex:[parentView.subviews count]];
[parentView addSubview:subview];

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
既存のサブビューの並び順を変更する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// subviewのインデックスを末尾に移動する(一番上に表示される)
[parentView bringSubviewToFront:subview];

// subviewのインデックスを先頭に移動する(一番後ろに表示される)
[parentView sendSubviewToBack:subview];  

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
最後に追加されたUIViewを削除する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
UIView *lastView = [self.view.subviews lastObject];
[lastView removeFromSuperview];

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
あるビューのサブビューであるかどうかチェックする
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
if ([targetView isDescendantOfView:self.view]) {
  NSLog(@"exist");
}else{
  NSLog(@"Doesn't exist");
}

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
xibファイルを用いて作成する
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
<UIViewのサブクラスを作成する>
<同名のxibファイルを作成する>
<上記xibファイルを編集する>
<Custom Class に上記クラス名をXibで指定する>
<下記メソッドを追加し、生成時に使用する>
+ (id)loadFromNib
{
  NSString *nibName = NSStringFromClass([self class]);
   UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
   return [nib instantiateWithOwner:nil options:nil][0];
}

または、
- (id)initWithFrame:(CGRect)frame
{
  self = [super initWithFrame:frame];
   if (self) {

      NSString *nibName = NSStringFromClass([self class]);
       UINib *nib = [UINib nibWithNibName:nibName bundle:nil];
       self = [nib instantiateWithOwner:nil options:nil][0];
   }
   return self;
}
最終更新:2018年02月28日 14:53