網站首頁 編程語言 正文
本文實例為大家分享了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
相關推薦
- 2023-03-28 react-native?封裝視頻播放器react-native-video的使用_React
- 2022-11-29 python中的import、from?import及import?as的區別解析_python
- 2022-04-15 C語言各種操作符透徹理解下篇_C 語言
- 2022-10-17 Kotlin編程循環控制示例詳解_Android
- 2023-07-22 BeanFactory和FactoryBean區別
- 2023-11-21 python使用print輸出不同顏色的字體、終端顯示不同顏色字體
- 2022-11-18 Redux模塊化拆分reducer函數流程介紹_React
- 2022-09-13 C++中string使用+號與int拼接方式_C 語言
- 最近更新
-
- 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同步修改后的遠程分支