網站首頁 編程語言 正文
本文實例為大家分享了iOS實現簡單分欄效果的具體代碼,供大家參考,具體內容如下
直接貼代碼嘍
GMSubfieldViiew.h
#import@interface GMSubfieldViiew : UIView /** ?* select index ?*/ @property(nonatomic,copy) void(^clickIndex)(NSInteger index); - (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)thiTitles; /** ?* ?默認勾選 ?*/ @property(nonatomic,assign) NSInteger selectedIndex; @end
GMSubfieldViiew.m
#import "GMSubfieldViiew.h" #define lineH 2 @interface GMSubfieldViiew () /** ?* ?titles ?*/ @property(nonatomic,strong) NSArray * titles; /** ?* ?lineView ?*/ @property(nonatomic,weak) UIView *lineView; /** ?* ?itemWidth ?*/ @property(nonatomic,assign) CGFloat itemWidth; @end @implementation GMSubfieldViiew #pragma mark - initUI - (instancetype)initWithFrame:(CGRect)frame titles:(NSArray *)thiTitles { ? ? if (self = [super initWithFrame:frame]) { ? ? ? ? self.titles = thiTitles; ? ? ? ? //initSubViews ? ? ? ? [self initSubViews]; ? ? } ? ? return self; } #pragma mark - action - (void) initSubViews { ? ? self.itemWidth = kScreen_Width/self.titles.count; ? ? //add child ? ? for (int i=0; i
調用:
GMSubfieldViiew *segView = [[GMSubfieldViiew alloc]initWithFrame:CGRectMake(0, 10, kScreen_Width, segH) titles:@[@"未還",@"已還"]]; ? ? segView.selectedIndex = 1; ? ? ESWeakSelf ? ? segView.clickIndex = ^(NSInteger index){ ? ? ? ? self.isHK = NO; ? ? ? ? ESStrongSelf ? ? ? ? if(index==0){ ? ? ? ? ? ? //未還 ? ? ? ? ? ? self.rightButton.hidden = NO; ? ? ? ? } ? ? ? ? else if(index==1){ ? ? ? ? ? ?//已還 ? ? ? ? ? ? self.rightButton.hidden = YES; ? ? ? ? ? ? self.containView.hidden = YES; ? ? ? ? } ? ? ? ? self.tableView.frame = CGRectMake(0, 60, kScreen_Width, kScreen_Height-NavHeight-60); ? ? ? ? [self.tableView reloadData]; ? ? }; ? ?[self.view addSubView:segView];
效果圖:
原文鏈接:https://blog.csdn.net/zww1984774346/article/details/53304235
相關推薦
- 2022-04-11 git 強行拉取覆蓋本地方法(Git強制覆蓋本地代碼)
- 2022-05-08 ASP.NET?MVC視圖尋址_實用技巧
- 2023-08-01 webpack 的熱更新及其原理
- 2022-11-07 將.py文件轉化為.exe文件的詳細過程_python
- 2023-08-13 基于TP5框架的excel導入功能
- 2023-01-07 Flutter?Widget開發之Focus組件圖文詳解_Android
- 2023-01-27 Python?Flask利用SocketIO庫實現圖表的繪制_python
- 2022-06-16 ASP.NET?Core?6.0?添加?JWT?認證和授權功能_實用技巧
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支