詳解iPhone開發應用為視圖加邊框
作者:佚名
iPhone開發應用為視圖加邊框是本文要介紹的內容,主要來介紹視圖中的一個有趣的案例,實現給視圖加邊框的效果,來看本文詳細內容。
iPhone開發應用為視圖加邊框是本文要介紹的內容,主要來介紹視圖中的一個有趣的案例,實現給視圖加邊框的效果,不多說,直接來看詳細內容講解。通過層(layer),可以給視圖增加邊框和圓角等。比如類似下面的效果,如圖:
寫法:
- - (void)loadView {
- [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation: UIStatusBarAnimationSlide];
- UIImageView *contentView = [[MyUIImageView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
- [contentView setImage:[UIImage imageNamed:@"1.jpg"]];
- [contentView setUserInteractionEnabled:YES];
- self.view=[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
- [self.view addSubview:contentView];
- self.view.backgroundColor=[UIColor blackColor];
- //為視圖增加邊框
- contentView.layer.masksToBounds=YES;
- contentView.layer.cornerRadius=20.0;
- contentView.layer.borderWidth=10.0;
- contentView.layer.borderColor=[[UIColor blueColor] CGColor];
- [contentView release];
- }
主要看文字注釋下面的四行代碼。也可以用上面注釋掉的代碼寫法,但沒有后面通過屬性設置簡明。
要完成這些代碼,需要引入QuartzCore庫。在頭文件中需要加入:
- #import <QuartzCore/QuartzCore.h>
在xcode項目的Frameworks部分加入,如圖:
小結:iPhone開發應用為視圖加邊框的內容介紹完了,希望通過本文的學習能對你有所幫助!
責任編輯:zhaolei
來源:
網絡轉載