你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> Objective-C完成自界說的半通明導航

Objective-C完成自界說的半通明導航

編輯:IOS開發綜合

本文實例為年夜家分享了Objective-C半通明導航的詳細完成代碼,供年夜家參考,詳細內容以下

#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
 
#import "RSwenNav.h"
 
@implementation RSwenNav
{
 UIVisualEffectView *effectview;
}
-(instancetype)initWithFrame:(CGRect)frame{
 self=[super initWithFrame:frame];
 if (self) {
  UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
 effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
 effectview.frame=frame;
 [self addSubview:effectview];
 [self addSubviews];
 }
 return self;
}
 
//添加導航子視圖
-(void)addSubviews{
 [self addSubview:self.backBtn];
 [self addSubview:self.titleLabel];
 [self addSubview:self.rightBtn];
 
}
-(UIButton *)backBtn{
 UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
 btn.frame=CGRectMake(20, 20, 60, 44);
 [btn setTitle:@"前往" forState:UIControlStateNormal];
 [btn addTarget:self action:@selector(RSwenNavback) forControlEvents:UIControlEventTouchUpInside];
 return btn;
}
 
-(UILabel *)titleLabel{
 UILabel * lable=[[UILabel alloc]init];
 lable.font=[UIFont systemFontOfSize:17];
 lable.textAlignment=NSTextAlignmentCenter;
 lable.frame=CGRectMake(100, 20, kScreenWidth-200, 44);
 lable.text=@"我的主頁";
 return lable;
}
 
-(UIButton *)rightBtn{
 UIButton * btn=[UIButton buttonWithType:UIButtonTypeCustom];
 btn.frame=CGRectMake([UIScreen mainScreen].bounds.size.width-100, 20, 80, 44);
 [btn setTitle:@"保留" forState:UIControlStateNormal];
 [btn addTarget:self action:@selector(rightBtnClicked) forControlEvents:UIControlEventTouchUpInside];
 return btn;
}
 
#pragma 事宜處置部門
 
//前往上個界面
-(void)RSwenNavback{
 //獲得UIView的下層UIViewController
 id object = [self nextResponder];
 while (![object isKindOfClass:[UIViewController class]] &&
  
  object != nil) {
  
 object = [object nextResponder];
  
 }
 UIViewController *uc=(UIViewController*)object;
 
 [uc.navigationController popViewControllerAnimated:YES];
}
 
//右邊按鈕被點擊
-(void)rightBtnClicked{
 if ([_delegate respondsToSelector:@selector(RSwenNavrightBtnClicked)]) {
 [_delegate RSwenNavrightBtnClicked];
 }
}
 
@end

以上就是本文的全體內容,願望對年夜家的進修有所贊助。

【Objective-C完成自界說的半通明導航】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!

  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved