IOS应用开发中UITableView的应用十分广泛,但是IOS7神一样的把UITableView拍扁了,这样一来IOS6的UITableView不干了,就吵着也要被拍扁,那好吧我今天就成全了你。。。


继上回书说道初步实现了一个QQ音乐的框架,但这远远不够,我是一个追求细节的人(就像锤子科技的老罗一样),怎么可能就这就结束了呢,下一步实现以下登陆的ModalView,比较简单没啥可说的直接上代码:

     UIColor *normalColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:]; //按钮默认状态的绿色
UIColor *selectedColor = [UIColor colorWithRed:/255.0 green:/255.0 blue:/255.0 alpha:]; //按钮点击状态的淡绿色
CGFloat navigationY = ;
if (IOS_7) {
navigationY = ;
} UINavigationBar *loginNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(, navigationY, , )]; //UINavigationBar的位置
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeSystem];
[cancelButton setFrame:CGRectMake(, , , )];
[cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[cancelButton setTitleColor:normalColor forState:UIControlStateNormal];
[[cancelButton titleLabel] setFont:[UIFont systemFontOfSize:]];
[cancelButton setTitleColor:selectedColor forState:UIControlStateHighlighted];
[cancelButton addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *cancelItem = [[UIBarButtonItem alloc] initWithCustomView:cancelButton]; //初始化取消按钮 UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeSystem];
[loginButton setFrame:CGRectMake(, , , )];
[loginButton setTitle:@"登陆" forState:UIControlStateNormal];
[loginButton setTitleColor:normalColor forState:UIControlStateNormal];
[[loginButton titleLabel] setFont:[UIFont systemFontOfSize:]];
[loginButton setTitleColor:selectedColor forState:UIControlStateHighlighted];
[loginButton addTarget:self action:@selector(loginAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *loginItem = [[UIBarButtonItem alloc] initWithCustomView:loginButton]; //初始化登陆按钮 UIImage *image = [UIImage imageNamed:@"input_login_line"]; UIImageView *userLineView = [[UIImageView alloc] initWithImage:image];
UIImageView *passwordLineView = [[UIImageView alloc] initWithImage:image]; //输入框下面的绿线 UITextField *userTextField = [[UITextField alloc] initWithFrame:CGRectMake(, +navigationY, , )];
[userTextField setPlaceholder:@"QQ号/手机/邮箱"];
[userTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[userTextField setKeyboardType:UIKeyboardTypeNumbersAndPunctuation];
[userTextField setReturnKeyType:UIReturnKeyNext];
[userLineView setFrame:CGRectMake(, +navigationY, , )]; UITextField *passwordTextField = [[UITextField alloc] initWithFrame:CGRectMake(, +navigationY, , )];
[passwordTextField setPlaceholder:@"密码"];
[passwordTextField setClearButtonMode:UITextFieldViewModeWhileEditing];
[passwordTextField setKeyboardType:UIKeyboardTypeASCIICapable];
[passwordTextField setReturnKeyType:UIReturnKeyDone];
[passwordLineView setFrame:CGRectMake(, +navigationY, , )]; UILabel *regStr = [[UILabel alloc] initWithFrame:CGRectMake(, +navigationY, , )];
[regStr setText:@"没有账号?点击这里"];
[regStr setFont:[UIFont systemFontOfSize:]];
[regStr setTextColor:[UIColor darkGrayColor]];
UILabel *greenStr = [[UILabel alloc] initWithFrame:CGRectMake(, +navigationY, , )];
[greenStr setText:@"快速注册"];
[greenStr setFont:[UIFont systemFontOfSize:]];
[greenStr setTextColor:normalColor]; UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:@"登陆"];
[navigationItem setLeftBarButtonItem:cancelItem];
[navigationItem setRightBarButtonItem:loginItem];
[loginNavigationBar pushNavigationItem:navigationItem animated:YES]; [self.view addSubview:loginNavigationBar];
[self.view addSubview:userTextField];
[self.view addSubview:userLineView];
[self.view addSubview:passwordTextField];
[self.view addSubview:passwordLineView];
[self.view addSubview:regStr];
[self.view addSubview:greenStr];

总结起来就是一个UINavigationBar,UINavigationBar上面有两个按钮,两个UITextField。只得说的事这个按钮,IOS7中把按钮的衣服扒掉了,这就直接导致我也要让IOS6的按钮也裸奔:

 [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor whiteColor] size:CGSizeMake(, )] forBarMetrics:UIBarMetricsDefault];

好了然后就没什么特别的了改改UITextField关联的键盘字体大小颜色什么的,效果图如下:


下面就是硬菜了,QQ音乐的界面UITableView采用的是UITableViewStyleGrouped类型的,但是在IOS6下UITableView有一个讨厌的灰不拉几的背景,我要把背景变为白色,使用如下代码:

     [tableView setBackgroundColor:[UIColor whiteColor]];
[tableView setBackgroundView:nil];

这样UITableView在IOS6中那讨厌的背景就没有了,但是UITableViewCell默认是圆角的很恶心,干掉:

     UIView *tempView = [[UIView alloc] init];
[cell setBackgroundView:tempView];

还要去掉cell点击时的圆角:

     cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor];

这里可以不用设置颜色的,而且现在这个颜色挺难看的,我还要继续修改

还有个问题IOS6的UITableViewCell默认不是与屏幕同宽的,需要自定义一个UItableViewCell复写 layoutSubviews 方法,代码如下:

 - (void) layoutSubviews {
[super layoutSubviews];
self.backgroundView.frame = CGRectMake(, , , );
self.selectedBackgroundView.frame = CGRectMake(, , , );
}

好了这样初步的适配完了,当然还有细节没有做到,继续学习吧,下面是我的音乐视图控制器的完整代码:

 //
// MyMusicViewController.m
// QQMusic
//
// Created by 赵 福成 on 14-5-21.
// Copyright (c) 2014年 ZhaoFucheng. All rights reserved.
// #import "MyMusicViewController.h"
#import "UIImage+CustomPureColor.h"
#import "UIButton+CustomButton.h"
#import "LoginViewController.h"
#import "CustomTableViewCell.h"
#define IOS_7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
@interface MyMusicViewController () @end @implementation MyMusicViewController NSArray *mainScreenCells;
NSArray *details;
NSArray *icon;
NSArray *iconSelected; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization self.title = @"我的音乐";
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //我的音乐按钮
UIButton *myMusicButton = [[UIButton alloc] initWithFrame:CGRectMake(, , , )];
[myMusicButton setImage:[UIImage imageNamed:@"defaultSinger"] forState:UIControlStateNormal];
[myMusicButton setImage:[UIImage imageNamed:@"defaultSinger"] forState:UIControlStateHighlighted];
// myMusicButton.userInteractionEnabled = NO;
myMusicButton.titleLabel.textAlignment = NSTextAlignmentLeft;
[myMusicButton addTarget:self action:@selector(login:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *myMusicButtonItem = [[UIBarButtonItem alloc] initWithCustomView:myMusicButton]; //播放界面按钮
UIBarButtonItem *nowPlayingButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[UIButton initNowPlayingButton]];
[self.navigationItem setLeftBarButtonItem:myMusicButtonItem];
[self.navigationItem setRightBarButtonItem:nowPlayingButtonItem]; mainScreenCells = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"全部歌曲", nil],[NSArray arrayWithObjects:@"我喜欢", @"全部歌单", nil],[NSArray arrayWithObjects:@"下载歌曲", @"最近播放", @"iPod歌曲", nil], nil]; details = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"0首在本地", nil], [NSArray arrayWithObjects:@"", @"", nil],[NSArray arrayWithObjects:@"0首", @"18首", @"0首", nil], nil]; icon = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"allsongs", nil], [NSArray arrayWithObjects:@"cell_like_in_my_music", @"", nil],[NSArray arrayWithObjects:@"down", @"recent_listen_icon", @"ipod", nil], nil]; iconSelected = [NSArray arrayWithObjects:[NSArray arrayWithObjects:@"allsongsSelected", nil], [NSArray arrayWithObjects:@"cell_like_in_my_music_pressed", @"", nil],[NSArray arrayWithObjects:@"downSelected", @"recent_listen_icon_h", @"ipodSelected", nil], nil]; UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStyleGrouped];
[tableView setDataSource:self];
if (!IOS_7) {
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
[tableView setBackgroundColor:[UIColor whiteColor]];
[tableView setBackgroundView:nil];
[tableView setDelegate:self];
[self.view addSubview:tableView]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return mainScreenCells.count;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[mainScreenCells objectAtIndex:section] count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellId = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[CustomTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellId];
}
NSUInteger rowNo = indexPath.row;
NSUInteger colNo = indexPath.section;
cell.textLabel.text = [[mainScreenCells objectAtIndex:colNo] objectAtIndex:rowNo];
if (!IOS_7) {
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(cell.frame.origin.x + , cell.frame.size.height, cell.frame.size.width - , 0.5)];
line.backgroundColor = [UIColor lightGrayColor];
[cell.contentView addSubview:line];
}
NSString *iconStr = (NSString *)[[icon objectAtIndex:colNo] objectAtIndex:rowNo];
NSString *iconSelectStr = (NSString *)[[iconSelected objectAtIndex:colNo] objectAtIndex:rowNo];
if (iconStr.length == && iconSelectStr.length == ) {
cell.imageView.image = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(, )];
cell.imageView.highlightedImage = [UIImage imageWithColor:[UIColor clearColor] size:CGSizeMake(, )];
}
else
{
cell.imageView.image = [UIImage imageNamed:iconStr];
cell.imageView.highlightedImage = [UIImage imageNamed:iconSelectStr];
} cell.detailTextLabel.text = [[details objectAtIndex:colNo] objectAtIndex:rowNo];
// [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
[cell setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow"]]]; //设置标题和描述背景透明
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor]; //去掉cell的圆角
UIView *tempView = [[UIView alloc] init];
[cell setBackgroundView:tempView]; //cell点击时的颜色
cell.selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
cell.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor]; return cell;
} - (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow_gedan"]]];
} - (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell setAccessoryView:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow"]]]; } - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 0.1;
} - (void)login:(UIButton *)sender
{
LoginViewController *loginView = [[LoginViewController alloc] init];
[self presentViewController:loginView animated:YES completion:^{ }];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} /*
#pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end

再来张效果图:

睡觉去了。。。。。。

山寨QQ音乐的布局(二)终于把IOS6的UITableView拍扁了的更多相关文章

  1. 山寨QQ音乐的布局(一)

    学了两天IOS趁着还没忘光,巩固一下所学知识想做点东西,由于自己的设计能力有限,所以就山寨一下吧,说到山寨怎么能忘了腾讯呢,今天发现QQ音乐的设计风格是扁平化的,小清新风格,所以就山寨一下它吧.. 由 ...

  2. 手把手教你使用Python抓取QQ音乐数据(第一弹)

    [一.项目目标] 获取 QQ 音乐指定歌手单曲排行指定页数的歌曲的歌名.专辑名.播放链接. 由浅入深,层层递进,非常适合刚入门的同学练手. [二.需要的库] 主要涉及的库有:requests.json ...

  3. Android 9 适配怎么做? “QQ音乐”优化实录

    WeTest 导读 2018年8月7日,Google对外发布最新 Android 9.0 正式版系统,并宣布系统版本Android P 被正式命名为代号“Pie”,最新系统已经正式推送包括谷歌Pixe ...

  4. 高仿手机QQ音乐之——Android带进度条的开关

    最新版的手机QQ音乐体验确实不错,发现首页播放按钮能够显示歌曲当前进度条.认为挺有新意.效果例如以下: 自己琢磨了下.能够用自己定义组件来实现,试着做了一下.效果例如以下: 整理了下思路.大概设计流程 ...

  5. (DNS被劫持所导致的)QQ音乐与视频网页打开很慢的解决方法

    这周开始发现一个很让人抓狂的现象,QQ音乐网页(http://y.qq.com)与QQ视频(http://v.qq.com/)网页打开超慢,甚至是无法打开,严重影响了业余的音乐视频生活. 以QQ视频为 ...

  6. QQ音乐的各种相关API

    QQ音乐的各种相关API 分类: oc2014-01-29 15:34 2676人阅读 评论(2) 收藏 举报 基本上论坛里做在线音乐的都在用百度的API,进来发现百度的API不仅歌曲的质量不可以保证 ...

  7. QQ音乐项目(OC版) - 实现细节

    QQ 音乐看似简单,但自己手动实现起来,才发现没有那么简单,有好多细节,需要注意. github : https://github.com/keenleung/QQMusic-OC 一.业务逻辑 首先 ...

  8. QQ音乐API分析记录

    我一直是QQ音乐的用户,最近想做一个应用,想用QQ音乐的API,搜索了很久无果,于是就自己分析QQ音乐的API. 前不久发现QQ音乐出了网页版的,是Flash的,但是,我用iPhone打开这个链接的时 ...

  9. 轻仿QQ音乐之音频歌词播放、锁屏歌词-b

    先上效果图 歌词播放界面 音乐播放界面 锁屏歌词界面 一. 项目概述 前面内容实在是太基础..只想看知识点的同学可以直接跳到第三部分的干货 项目播放的mp3文件及lrc文件均来自QQ音乐 本文主要主要 ...

随机推荐

  1. 编译boost python模块遇到的错误:../../libraries/boost_1_44_0/boost/python/detail/wrap_python.hpp:75:24: fatal error: patchlevel.h: No such file or directory

    就是遇到类似标题上面的错误. 原因是没有安装对应python的python-dev依赖,不然编译到boost python模块的时候就会出错. 所以解决方案是sudo apt-get install ...

  2. Linux用户与用户组,UID及GID

    以下列出文章: Linux系统下如果查看用户的UID和GID:http://blog.csdn.net/ahangliu/article/details/7567444 Linux的用户和用户组管理: ...

  3. C语言随笔_区分=与==

    写C程序时,经常发现大家=与==分不清.最常见的写法如下:int a = 3;if(a = 1){.......} 写程序的人原意是想如果a等于1的话,就执行花括号里的语句,a初始化时的值是3,也就是 ...

  4. ZOJ 1136 Multiple (BFS)

    Multiple Time Limit: 10 Seconds      Memory Limit: 32768 KB a program that, given a natural number N ...

  5. Bring Your Charts to Life with HTML5 Canvas and JavaScript

    Bring Your Charts to Life with HTML5 Canvas and JavaScript Bring Your Charts to Life with HTML5 Canv ...

  6. 一、crond简介

    crond 是linux下用来周期性的执行某种任务或等待处理某些事件的一个守护进程,与windows下的计划任务类似,当安装完成操作系统后,默认会安装此服务 工具,并且会自动启动crond进程,cro ...

  7. lua 类实现

    Class={}; Class.classList={}; --保存所有已经定义过的类 --类的类型: 类和接口, 接口也是一种类 Class.TYPE_CLASS="Class" ...

  8. 如何把UIView转成UIImage,解决模糊失真问题

    最近工作中,遇到一个需求,需要把一个UIView对象转成UIImage对象显示.经过网络搜索,找到如下答案: ? 1 2 3 4 5 6 7 8 -(UIImage*)convertViewToIma ...

  9. RMAN备份各种物理文件

    RMAN运行脚本的方式:RMAN TARGET / @backup_db.rmanRMAN TARGET / cmdfile=backup_db.rman在RMAN中执行操作系统中保存的脚本:RMAN ...

  10. HTML 5 全局属性和事件属性

    1.HTML 5 全局属性 HTML 属性能够赋予元素含义和语境. 下面的全局属性可用于任何 HTML5 元素. NEW:HTML 5 中新的全局属性. 属性 描述 accesskey 规定访问元素的 ...