美文网首页
个人页面

个人页面

作者: 淘代码者 | 来源:发表于2017-08-11 18:02 被阅读0次

效果如图:


QQ20170811-180048-HD.gif
//
//  ViewController.m
//  MineUI
//
//  Created by apple on 17/8/11.
//  Copyright © 2017年 Wang. All rights reserved.
//

#import "ViewController.h"

#define KScreen_Width [UIScreen mainScreen].bounds.size.width
#define KScreen_Height [UIScreen mainScreen].bounds.size.height

static const CGFloat kBackImageHeight = 280;
static const CGFloat kHeadImageHeight = 80;

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *backImage;
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIImageView *headImage;
@property (nonatomic, strong) UILabel *userNameLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIBarButtonItem *rightBtn;
@property (nonatomic, strong) UIBarButtonItem *leftBtn;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.view addSubview:self.tableView];
    [self.tableView addSubview:self.backImage];
    [self.tableView addSubview:self.backView];
    [self.backView addSubview:self.headImage];
    [self.backView addSubview:self.userNameLabel];
    self.navigationItem.titleView = self.titleLabel;
    self.navigationItem.leftBarButtonItem = self.leftBtn;
    self.navigationItem.rightBarButtonItem = self.rightBtn;
}

-(void)viewWillAppear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
}

- (void)viewWillDisappear:(BOOL)animated{
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    [self.navigationController.navigationBar setShadowImage:nil];
}

#pragma mark - lazy method
- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]init];
        _tableView.frame = [UIScreen mainScreen].bounds;
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.contentInset = UIEdgeInsetsMake(kBackImageHeight, 0, 0, 0);
    }
    return _tableView;
}

- (UIImageView *)backImage{
    if (!_backImage) {
        _backImage = [[UIImageView alloc]init];
        _backImage.frame = CGRectMake(0, - kBackImageHeight, KScreen_Width, kBackImageHeight);
        _backImage.contentMode = UIViewContentModeScaleAspectFill;
        _backImage.image = [UIImage imageNamed:@"background"];
    }
    return _backImage;
}

- (UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc]init];
        _backView.frame = self.backImage.frame;
        _backView.backgroundColor = [UIColor clearColor];
    }
    return _backView;
}

- (UIImageView *)headImage{
    if (!_headImage) {
        _headImage = [[UIImageView alloc]init];
        _headImage.frame = CGRectMake((KScreen_Width - kHeadImageHeight)/2, kHeadImageHeight, kHeadImageHeight, kHeadImageHeight);
        _headImage.image = [UIImage imageNamed:@"1.jpg"];
        _headImage.contentMode = UIViewContentModeScaleAspectFill;
        _headImage.layer.cornerRadius = kHeadImageHeight/2;
        _headImage.layer.masksToBounds = YES;
    }
    return _headImage;
}

- (UILabel *)userNameLabel{
    if (!_userNameLabel) {
        _userNameLabel = [[UILabel alloc]init];
        _userNameLabel.frame = CGRectMake(0, CGRectGetMaxY(self.headImage.frame) + 10, KScreen_Width, 22);
        _userNameLabel.text = @"wangyu";
        _userNameLabel.font = [UIFont italicSystemFontOfSize:15.f];
        _userNameLabel.backgroundColor = [UIColor clearColor];
        _userNameLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _userNameLabel;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
        _titleLabel.textColor = [UIColor whiteColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = @"个人中心";
        _titleLabel.alpha = 0;
    }
    return _titleLabel;
}

- (UIBarButtonItem*)rightBtn{
    if (!_rightBtn) {
        UIButton *rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
        [rightBtn setTitle:@"设置" forState:UIControlStateNormal];
        rightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [rightBtn addTarget:self action:@selector(rightBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _rightBtn=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    }
    return _rightBtn;
}

- (UIBarButtonItem*)leftBtn{
    if (!_leftBtn) {
         UIButton *leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 30)];
        [leftBtn setTitle:@"返回" forState:UIControlStateNormal];
        leftBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [leftBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [leftBtn addTarget:self action:@selector(leftBtnAction) forControlEvents:UIControlEventTouchUpInside];
        _leftBtn = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
    }
    return _leftBtn;
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.textLabel.text = [NSString stringWithFormat:@"haha%ld",indexPath.row];
    return cell;
}

#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if ([scrollView isKindOfClass:[UITableView class]]) {
        CGFloat yOffset = scrollView.contentOffset.y;
        
        CGRect newFrame = self.backImage.frame;
        if (yOffset < -kBackImageHeight) {
            newFrame.origin.y = yOffset;
            newFrame.size.height = -yOffset;
        }
        self.backImage.frame = newFrame;
        
        CGFloat alpha = (yOffset + kBackImageHeight)/kBackImageHeight;
        [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor cyanColor] colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
        self.titleLabel.alpha = alpha;
        alpha = fabs(alpha);
        alpha = fabs(1 - alpha);
        alpha = alpha < 0.2 ? 0 : alpha - 0.2;
        self.backView.alpha = alpha;
    }
}

#pragma mark - action
- (void)rightBtnAction{
    NSLog(@"点击右边按钮了");
    
}

- (void)leftBtnAction{
    NSLog(@"点击左边边按钮了");
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - private method
- (UIImage *)imageWithColor:(UIColor *)color{
    // 描述矩形
    CGRect rect           = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    
    // 开启位图上下文
    UIGraphicsBeginImageContext(rect.size);
    // 获取位图上下文
    CGContextRef context  = UIGraphicsGetCurrentContext();
    // 使用color演示填充上下文
    CGContextSetFillColorWithColor(context, [color CGColor]);
    // 渲染上下文
    CGContextFillRect(context, rect);
    // 从上下文中获取图片
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    // 结束上下文
    UIGraphicsEndImageContext();
    return theImage;
}

@end

相关文章

  • 个人页面

    效果如图: @end

  • 个人页面

    yemian .box{width:1436px;height...

  • HTML个人博客页面

    知识点总结:下面的是一个个人博客页面,歌词的段落用的时“p”标签,超链接为“a”标签。包括鼠标经过的事件:颜色变换...

  • 个人订单页面开发

    一页面主要部分 二碰到问题 三常用的布局方式

  • 个人博客—页面导航

    个人博客—页面导航 鼠标滑过导航项时,蓝色背景图片从起始位置紧跟鼠标滑到,随后白色文字滑动到对应导航项; 鼠标滑出...

  • 个人信息页面

    个人信界面设计效果 页面布局 页面布局相较于登录界面更复杂,不适合所有元素使用绝对定位,由于小程序自带有chrom...

  • 控制器跳转时导航栏透明与不透明的渐变效果实现

    APP中个人页面的一级页面 导航栏透明,下级页面不透明,实现切换时导航栏渐变效果。类似于QQ 的个人页面那种用类别...

  • 搭配个人中心

    跳转该个人中心页面:未登录正常跳转个人中心页面:已登录(非登录账号)正常跳转个人中心页面:已登录(登录账号)

  • layui前台页面填充

    完善个人资料页面,baby信息页面,向记录模块进发

  • 入门任务 14

    1.作品展示页面 2.个人简历页面

网友评论

      本文标题:个人页面

      本文链接:https://www.haomeiwen.com/subject/sasrrxtx.html