a UIScrollView *toScrollView
(画面の幅) に、灰色の下境界線 (iPhone のネイティブ メッセージ アプリの作成ビューの宛先フィールドとまったく同じ) を追加します。
これを達成するために、私はCocoa Touch: UIView の境界線の色と太さを変更するにはどうすればいいですか?そして、上部の境界線をカスタムで覆いUINavigationBar
、toScrollView
x 座標を -1、幅を 322 にして、左と右の境界線が画面から外れるようにしました。
これは問題なさそうですが、一種のハックなので、もっと良い方法があるのではないかと考えていました。
- (void)viewDidLoad {
[super viewDidLoad];
// Add UINavigationBar *navigationBar at top.
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:@selector(cancelAction)];
UINavigationBar *navigationBar = [[UINavigationBar alloc]
initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
navigationBar.items = [NSArray arrayWithObject:self.navigationItem];
// Add UIScrollView *toScrollView below navigationBar.
UIScrollView *toScrollView = [[UIScrollView alloc]
initWithFrame:CGRectMake(-1.0f, 43.0f, 322.0f, 45.0f)];
toScrollView.backgroundColor = [UIColor whiteColor];
toScrollView.layer.borderColor = [UIColor colorWithWhite:0.8f alpha:1.0f].CGColor;
toScrollView.layer.borderWidth = 1.0f;
[self.view addSubview:toScrollView];
[self.view addSubview:navigationBar]; // covers top of toScrollView
}
ベストアンサー1
UIView
@ImreKelényi が提案しているように、を使用する代わりに、を使用できますCALayer
。
// Add a bottomBorder.
CALayer *bottomBorder = [CALayer layer];
bottomBorder.frame = CGRectMake(0.0f, 43.0f, toScrollView.frame.size.width, 1.0f);
bottomBorder.backgroundColor = [UIColor colorWithWhite:0.8f
alpha:1.0f].CGColor;
[toScrollView.layer addSublayer:bottomBorder];