山寨QQ音乐的布局(二)终于把IOS6的UITableView拍扁了
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拍扁了的更多相关文章
- 山寨QQ音乐的布局(一)
学了两天IOS趁着还没忘光,巩固一下所学知识想做点东西,由于自己的设计能力有限,所以就山寨一下吧,说到山寨怎么能忘了腾讯呢,今天发现QQ音乐的设计风格是扁平化的,小清新风格,所以就山寨一下它吧.. 由 ...
- 手把手教你使用Python抓取QQ音乐数据(第一弹)
[一.项目目标] 获取 QQ 音乐指定歌手单曲排行指定页数的歌曲的歌名.专辑名.播放链接. 由浅入深,层层递进,非常适合刚入门的同学练手. [二.需要的库] 主要涉及的库有:requests.json ...
- Android 9 适配怎么做? “QQ音乐”优化实录
WeTest 导读 2018年8月7日,Google对外发布最新 Android 9.0 正式版系统,并宣布系统版本Android P 被正式命名为代号“Pie”,最新系统已经正式推送包括谷歌Pixe ...
- 高仿手机QQ音乐之——Android带进度条的开关
最新版的手机QQ音乐体验确实不错,发现首页播放按钮能够显示歌曲当前进度条.认为挺有新意.效果例如以下: 自己琢磨了下.能够用自己定义组件来实现,试着做了一下.效果例如以下: 整理了下思路.大概设计流程 ...
- (DNS被劫持所导致的)QQ音乐与视频网页打开很慢的解决方法
这周开始发现一个很让人抓狂的现象,QQ音乐网页(http://y.qq.com)与QQ视频(http://v.qq.com/)网页打开超慢,甚至是无法打开,严重影响了业余的音乐视频生活. 以QQ视频为 ...
- QQ音乐的各种相关API
QQ音乐的各种相关API 分类: oc2014-01-29 15:34 2676人阅读 评论(2) 收藏 举报 基本上论坛里做在线音乐的都在用百度的API,进来发现百度的API不仅歌曲的质量不可以保证 ...
- QQ音乐项目(OC版) - 实现细节
QQ 音乐看似简单,但自己手动实现起来,才发现没有那么简单,有好多细节,需要注意. github : https://github.com/keenleung/QQMusic-OC 一.业务逻辑 首先 ...
- QQ音乐API分析记录
我一直是QQ音乐的用户,最近想做一个应用,想用QQ音乐的API,搜索了很久无果,于是就自己分析QQ音乐的API. 前不久发现QQ音乐出了网页版的,是Flash的,但是,我用iPhone打开这个链接的时 ...
- 轻仿QQ音乐之音频歌词播放、锁屏歌词-b
先上效果图 歌词播放界面 音乐播放界面 锁屏歌词界面 一. 项目概述 前面内容实在是太基础..只想看知识点的同学可以直接跳到第三部分的干货 项目播放的mp3文件及lrc文件均来自QQ音乐 本文主要主要 ...
随机推荐
- NOI十连测 第六测 T3
思路:考试的时候我非常地**,写了圆并,然后还TM写了半平面交和三角剖分,虽然只有30分..但是看在我写了500行的份上还是挂着吧.. #include<cstdio> #include& ...
- WPF笔记(1.6 数据绑定)——Hello,WPF!
原文:WPF笔记(1.6 数据绑定)--Hello,WPF! 这个一节都是在讲一个数据绑定的示例.功用:输入姓和名,点击Add按钮,ListBox增加一条记录,永远是字符串“name: nick”:L ...
- 【转】如何定制android源码的编译选项 & 后期安装? ---- 不错
原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd0100z3o9.html Android编译过程比较长,配置起来也很麻烦.现仅就工作遇到的问题做个总结.所用硬 ...
- GNU C - 关于8086的内存访问机制以及内存对齐(memory alignment)
一.为什么需要内存对齐? 无论做什么事情,我都习惯性的问自己:为什么我要去做这件事情? 是啊,这可能也是个大家都会去想的问题, 因为我们都不能稀里糊涂的或者.那为什么需要内存对齐呢?这要从cpu的内存 ...
- Php环境下载(PHPNow)安装
下载 From http://servkit.org/download 安装 解压下载包,双击setup.cmd,按照提示执行安装. 安装成功测试 原来的解压目录
- Word Ladder II 解答
Question Given two words (beginWord and endWord), and a dictionary's word list, find all shortest tr ...
- lowerCaseTableNames
数据库表,数据库名大小写铭感问题 mysql lower-case-table-names参数 线上有业务用到开源的产品,其中SQL语句是大小写混合的,而建表语句都是小写的,mysql默认设置导致这些 ...
- Pattern | CLiPS
Pattern | CLiPS Pattern Pattern is a web mining module for the Python programming language. It has t ...
- Wine --- Linux上运行 Windows 应用
https://www.winehq.org/ Wine (“Wine Is Not an Emulator” 的首字母缩写)是一个能够在多种 POSIX-compliant 操作系统(诸如 Linu ...
- 文件MD5
package mainimport ( "crypto/md5" "fmt" // "github.com/astaxie/bee ...