网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

iOSUITableView的横向滑动

    在开发中横向滑动我们通常会想到用UICollectionView,确实这个好用,但有时候需求不太明确而且用UICollectionView的头部需要自定义没有UITableView简单,粽子看需求,根据需求决定,但是我们得会这种技能。

为谯城等地区用户提供了全套网页设计制作服务,及谯城网站建设行业解决方案。主营业务为网站设计、成都网站制作、谯城网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!

@interface ViewController ()

@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 进行全局设置
    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

解决问题的方法不止一种,要多想想其他的解决办法,这样才能更好的掌握每个知识点,说不定会更好,说不定就是面试题等待。


本文题目:iOSUITableView的横向滑动
本文网址:http://bjjierui.cn/article/gioepe.html

其他资讯