1. create a subclass of UIView: newView
2. create a view xib: newView.xib
3. In IB, set view's class as newView
4. In xCode, add new view
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"newView" owner: self
options:nil];
UIView *view = [nib objectAtIndex: 1];
[self.view addSubview:view];
note: use the index for array of nib to get specific object, such as view
method 2: all within xCode:
CGRect newViewFrame = CGRectMake(0, 0, 50, 50);
UIView *newView = [[UIView alloc] initWithFrame:newViewFrame];
newView.backgroundColor = [UIColor blueColor];
[self.view addSubview:newView];
沒有留言:
張貼留言