在開發(fā)中橫向滑動(dòng)我們通常會想到用UICollectionView,確實(shí)這個(gè)好用,但有時(shí)候需求不太明確而且用UICollectionView的頭部需要自定義沒有UITableView簡單,粽子看需求,根據(jù)需求決定,但是我們得會這種技能。
為譙城等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及譙城網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、譙城網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property(strong,nonatomic)UITableView *myTableView; @end @implementation ViewController - (UITableView *)myTableView{ if(!_myTableView){ CGRect tableViewRect = CGRectMake(0, 0,100, CGRectGetWidth(self.view.frame)); _myTableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; _myTableView.dataSource = self; _myTableView.delegate = self; _myTableView.frame = tableViewRect; _myTableView.separatorStyle = NO; _myTableView.backgroundColor = [UIColor grayColor]; _myTableView.transform = CGAffineTransformMakeRotation(-M_PI / 2); _myTableView.showsVerticalScrollIndicator = NO; _myTableView.center = CGPointMake(self.view.frame.size.width / 2, 50); } return _myTableView; } - (void)viewDidLoad { [super viewDidLoad]; //AppDelegate 進(jìn)行全局設(shè)置 if (@available(iOS 11.0, *)){ [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; } self.view.backgroundColor = [UIColor purpleColor]; [self.view addSubview:self.myTableView]; // Do any additional setup after loading the view, typically from a nib. } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ return 100; } -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return 50; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ FFTableViewCell *cell = [FFTableViewCell cellWithTableView:tableView]; return cell; } #pragma mark 選中的方法 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ [tableView deselectRowAtIndexPath:indexPath animated:YES]; } #import "FFTableViewCell.h" @interface FFTableViewCell() @property(strong,nonatomic)UIButton *monthBtn; @end @implementation FFTableViewCell static NSString *cellID = @"FFTableViewCell"; - (UIButton *)monthBtn{ if(!_monthBtn){ _monthBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _monthBtn.backgroundColor = [UIColor redColor]; _monthBtn.layer.cornerRadius = 30.0f; _monthBtn.clipsToBounds = YES; [_monthBtn setTitle:@"在干嘛" forState:UIControlStateNormal]; } return _monthBtn; } - (void)awakeFromNib { [super awakeFromNib]; // Initialization code } + (instancetype)cellWithTableView:(UITableView *)tableView { FFTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[FFTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell; } - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if(self){ self.contentView.transform = CGAffineTransformMakeRotation(M_PI / 2); [self.contentView addSubview:self.monthBtn]; } return self; } - (void)layoutSubviews{ [super layoutSubviews]; _monthBtn.frame = CGRectMake((CGRectGetWidth(self.contentView.frame)-60)/2, (CGRectGetHeight(self.contentView.frame)-60)/2, 60,60); } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } - (void)dealloc{ _monthBtn = nil; } @end
解決問題的方法不止一種,要多想想其他的解決辦法,這樣才能更好的掌握每個(gè)知識點(diǎn),說不定會更好,說不定就是面試題等待。
本文題目:iOSUITableView的橫向滑動(dòng)
URL鏈接:http://chinadenli.net/article34/gioepe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供服務(wù)器托管、網(wǎng)站設(shè)計(jì)公司、搜索引擎優(yōu)化、品牌網(wǎng)站建設(shè)、、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)