用圖片設定backgroundColor
圖片將重覆排列
ex:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"mainBackground.png"]];
UIBarButtonItem
背景圖片高度
30px (60px retina display) = portrait
24px (48px retina display) = landscape
UIImage *backButtonImage = [UIImage imageNamed:@"test.png"];
固定左右的寬度
backButtonImage = [backButtonImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, 6, 0, 6)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
比較字少跟字多的樣子
圖片高度的影響
redButton.png: 70*70, 140*140
UIImage *barButtonImage = [UIImage imageNamed:@"redButton.png"];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
UIBarButtonItem *saveButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(save:)];
self.navigationItem.rightBarButtonItem = saveButtonItem;
y軸置中於navigation bar。button高度等於原來圖片高度
圖片高度小於30 points會被放大成30 points
圖片高度大於30 points會維持原高度
UINavigationBar
UINavigationController *navController = [[UINavigationController alloc]
initWithRootViewController:controller];
// 圖片size: 320*44, 640*88
UIImage *menuBarImage = [UIImage imageNamed:@"bar.png"];
[navController.navigationBar setBackgroundImage:menuBarImage
forBarMetrics:UIBarMetricsDefault];
如果將bar設為translucent,要記得同時將clipsToBounds設為YES
navController.navigationBar.translucent = YES;
navController.navigationBar.clipsToBounds = YES;
clipsToBounds沒有設定YES時,多出一條線
clipsToBounds設定YES時
UIButton
如果沒有設定contentMode,預設的圖片比例是?
設定UIViewContentModeScaleAspectFill的圖片
photoBut.imageView.contentMode = UIViewContentModeScaleAspectFill;
[photoBut setImage:choosenImage forState:UIControlStateNormal];
if([[[UIDevice currentDevice] systemVersion] intValue] < 6)
{
photoBut.adjustsImageWhenHighlighted = NO;
}
如果圖片size小於button的大小,利用setImage設定的圖片將維持圖片原來的size置中。UIImageView沒有這個問題。
UITextField
bmrTextField.background = image;
沒有留言:
張貼留言