日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

iOS實現簡單分欄效果_IOS

作者:小溪彼岸 ? 更新時間: 2022-05-23 編程語言

本文實例為大家分享了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

欄目分類
最近更新