在找靓机苹果买手机送耳机活不会上当受骗

30021人阅读
iphone(160)
& &在Xcode5上做以上的操作没有问题,这次是要在Xcode6上实现之,特记录以备用.
& 首先新建一个storyboard文件.取名Custom.storyboard.拖动菜单添加一个TabBarComtroller.由于XCode6使用了Use Size Classes功能.所有拖出来的Controller都是600x800大小.见图
恢复到以前的界面(恢复到Xcode6以前的界面,这个是为了习惯之前界面的人士):
通过取消Use Size Classes项并选择Disable Size Classes.如下图
& & 然后选择适配ios6.1 and Later.下图:
然后结果就是下图,
这时候的视图就是iphone5了(尺寸为320x568)
继续下面的
从菜单项中拖出一个TabBarComtroller,默认情况有两项(Item1和Item2).我们这里修改为Home,List.
这里有些技巧(单击storyboard空白的地方可以放大或缩小各个视图,Xcode之前的版本是有放大缩小两按钮的.
这里注意缩小视图情况下能做什么事情,放大视图上能做什么事情.)
&缩小视图:
& & & a.移动视图位置;
& & & b.建立
&& & c.设置视图的Custom class(右边菜单的第三项),而在放大视图设置不了Class.
&放大视图:
&& & a.向视图中加入Button等子视图(缩小情况是不能做的);
&& & b.可以建立属性(IB)关系.
继续下面的
从菜单中在拖出一个ViewController(当然也可以拖出一个Navigation Controller).缩小情况下调整各个视图的位置,选中Tab bar Controller,按住Ctrl键并拖动鼠标,到新建的ViewController视图上,松开Ctrl键和鼠标,在弹出的菜单中选择RelationsShip Segues中的View Controllers.这样就出现新的Item.就可以重新命名新的项了.如图
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:941899次
积分:8566
积分:8566
排名:第1844名
原创:106篇
转载:113篇
评论:95条
(3)(2)(1)(1)(1)(1)(2)(1)(4)(4)(2)(1)(8)(8)(3)(11)(2)(1)(7)(13)(4)(8)(3)(6)(6)(4)(7)(11)(10)(11)(2)(7)(7)(1)(1)(2)(1)(9)(1)(1)(1)(1)(2)(7)(1)(1)(5)(1)(9)(1)(1)(2)(1)(1)(3)(1)(1)(3)(2)(1)(1)(2)(1)(3)(1)(1)(1)(2)3655人阅读
一 在这里先说一种建立tablebar的方法 & 建立一个自定义的环境context &自定义的图标 &以及与NavgationBar 的联系方式
1. & 建立哟个自定义环境
CGContextRef MyCreateBitmapContext (int pixelsWide,int pixelsHigh)
CGContextRef
context = NULL;
CGColorSpaceRef colorS
bitmapByteC
bitmapBytesPerR
bitmapBytesPerRow
= (pixelsWide * 4);
bitmapByteCount
= (bitmapBytesPerRow * pixelsHigh);
colorSpace = CGColorSpaceCreateDeviceRGB();
bitmapData = malloc( bitmapByteCount );
if (bitmapData == NULL)
fprintf (stderr, &Memory not allocated!&);
CGColorSpaceRelease( colorSpace );
return NULL;
context = CGBitmapContextCreate (bitmapData,
pixelsWide,
pixelsHigh,
bitmapBytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast);
if (context== NULL)
free (bitmapData);
fprintf (stderr, &Context not created!&);
return NULL;
CGColorSpaceRelease( colorSpace );
2. 制作一个圆角的图片
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,float ovalHeight)
context 为环境 rect为所截取图片的大小 后面的两个参数为图片将要缩放的宽高比例
static void addRoundedRectToPath(CGContextRef context, CGRect rect, float ovalWidth,float ovalHeight)
if (ovalWidth == 0 || ovalHeight == 0)
CGContextAddRect(context, rect);
/*CGContextSaveGState与CGContextRestoreGState的作用
使用Quartz时涉及到一个图形上下文,其中图形上下文中包含一个保存过的图形状态堆栈。在Quartz创建图形上下文时,
该堆栈是空的CGContextSaveGState函数的作用是将当前图形状态推入堆栈。之后,您对图形状态所做的修改会影响
随后的描画操作,但不影响存储在堆栈中的拷贝。在修改完成后,您可以通过CGContextRestoreGState函数把堆栈顶
部的状态弹出,返回到之前的图形状态。这种推入和弹出的方式是回到之前图形状态的快速方 法,避免逐个撤消所有的状态
修改;这也是将某些状态(比如裁剪路径)恢复到原有设置的唯一方式。*/
/*CGRectGetMinX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最左边)
CGRectGetMaxX方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最右边)
CGRectGetMinY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最小值(位于屏幕的最上边)
CGRectGetMaxY方法的作用得到目前scrollview在当前屏幕中相对于整个UIScrollView的最大值(位于屏幕的最下边*/
/*void CGContextAddArc(CGContextRef c,CGFloat x,CGFloat y,CGFloat radius,CGFloat startAngle,
CGFloat endAngle, int clockwise)
x,y为圆点坐标,startAngle为开始的弧度,endAngle为
结束的弧度,clockwise 0为顺时针,1为逆时针。*/
/*void CGContextAddArcToPoint(CGContextRef c,CGFloat x1,CGFloat y1,CGFloat x2,CGFloat y2,
CGFloat radius);
使用该函数绘制圆弧前,首先要确定一个start point.
CGContextMoveToPoint(context, 100, 100);
然后设置CGContextAddArcToPoint(context, 50, 100, 50, 150, 50);这里是从起始点100,100开始到第一个点
50,100画一条线段,然后再从第一个点50,100到第二点150,50画另一条线段,然后设置半径为50.通过相交的两条线段的夹
角处画此半径的圆弧就可以确定圆弧了。*/
CGContextSaveGState(context);
CGContextTranslateCTM(context, CGRectGetMinX(rect), CGRectGetMinY(rect));
//移动 改变这张画纸坐标轴的x,y偏移量
CGContextScaleCTM(context, ovalWidth, ovalHeight); //缩放 后两个参数是改变坐标轴x,y单位大小比例
fw = CGRectGetWidth(rect) / ovalW
fh = CGRectGetHeight(rect) / ovalH
CGContextMoveToPoint
(context, fw, fh/2);
// 在右下角开始
CGContextAddArcToPoint(context, fw, fh, fw/2, fh, 1); // 右上角
CGContextAddArcToPoint(context, 0, fh, 0, fh/2, 1);
CGContextAddArcToPoint(context, 0, 0, fw/2, 0, 1);
CGContextAddArcToPoint(context, fw, 0, fw, fh/2, 1); // 回到右下角
CGContextClosePath(context);
CGContextRestoreGState(context);
3. 给所制作的圆角图形 涂上颜色 制成一幅图片
id createImage(float percentage)
CGContextRef context
= MyCreateBitmapContext(30, 30);
addRoundedRectToPath(context, CGRectMake(0.0f, 0.0f, 30.0f, 30.0f), 4.0f, 4.0f);
CGFloat gray[4] = {percentage, percentage, percentage, 1.0f};
CGContextSetFillColor(context, gray);
CGContextFillPath(context);
CGImageRef myRef = CGBitmapContextCreateImage (context);
free(CGBitmapContextGetData(context));
CGContextRelease(context);
return [UIImage imageWithCGImage:myRef];
4.初始化tabBar的按钮标题 和图片
-(BrightnessController *) initWithBrightness: (int) aBrightness
self = [super init];
brightness = aB
self.title = [NSString stringWithFormat:@&%d%%&, brightness * 10];
[self.tabBarItem initWithTitle:self.title image:createImage(((float) brightness / 10.0f)) tag:0];
5.在AppDelegate中 &声明一个数组 来保存tableBar中所有的按钮 这里用到了for循环
NSMutableArray *controllers = [[NSMutableArray alloc] init];
for (int i = 0; i & 11; i++)
BrightnessController *bControl = [[BrightnessController alloc]
initWithBrightness:i];
UINavigationController *nav = [[UINavigationController alloc]
initWithRootViewController:bControl];
nav.navigationBar.barStyle = UIBarStyleBlackT
[controllers addObject:nav];
[bControl release];
[nav release];
/*可定制按钮
默认情况下,当按钮多于5个时,标签栏控制器允许拥护对按钮布局进行定制。要做到这一点,可以单击标有“更多”的标签,
然后单击随之出现的导航栏上的编辑按钮。你可以选择只对某些特定的标签进行定制,也可以完全禁止定制。要允许定制,
请将标签栏控制器的 customizableViewControllers 设置为一个数组,数组中包含有你希望用户进行定制的试图控制器:*/
UITabBarController *tbarController = [[UITabBarController alloc] init];
tbarController.viewControllers =
tbarController.customizableViewControllers =
tbarController.delegate =//这里有个代理 功能就是在你选择和更换试图的时候记录你的这次的操作一方便下次使用连续性和方便性
[window addSubview:tbarController.view];
二.有几个视图 就添加几个UIViewController的文件
在AppDelegate中&
IViewController *viewController1 = [[File1 alloc]init];
UIViewController *viewController2 = [[File2 alloc]init];
UIViewController *viewController3 = [[File3 alloc]init];
UIViewController *viewController4 = [[File4 alloc]init];
UINavigationController *viewController5 =[[UINavigationController alloc]
initWithRootViewController:[[File5 alloc]init]];
UITabBarController *tableBar = [[UITabBarController alloc] init];
tableBar.viewControllers = [NSArray arrayWithObjects:viewController1
viewController2,viewController3,viewController4,
viewController5,nil];
self.window.rootViewController = tableB
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:121576次
积分:1453
积分:1453
排名:千里之外
原创:24篇
转载:21篇
(2)(1)(1)(4)(4)(4)(3)(1)(2)(11)(12)iOS开发UI篇—UITabBarController简单介绍 - 文顶顶 - 博客园
最怕你一生碌碌无为 还安慰自己平凡可贵
iOS开发UI篇&UITabBarController简单介绍
一、简单介绍
UITabBarController和UINavigationController类似,UITabBarController也可以轻松地管理多个控制器,轻松完成控制器之间的切换,典型的例子就是QQ、微信等应?。
二、UITabBarController的使用
1.使用步骤:
(1)初始化UITabBarController
(2)设置UIWindow的rootViewController为UITabBarController
(3)创建相应的子控制器(viewcontroller)
(4)把子控制器添加到UITabBarController
2.代码示例
新建一个空的文件,在Application的代理中编码
YYAppDelegate.m文件
YYAppDelegate.m
01-UITabBar控制器基本使用
Created by 孔医己 on 14-6-7.
Copyright (c) 2014年 itcast. All rights reserved.
9 #import "YYAppDelegate.h"
11 @implementation YYAppDelegate
13 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
//1.创建Window
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
//a.初始化一个tabBar控制器
UITabBarController *tb=[[UITabBarController alloc]init];
//设置控制器为Window的根控制器
self.window.rootViewController=
//b.创建子控制器
UIViewController *c1=[[UIViewController alloc]init];
c1.view.backgroundColor=[UIColor grayColor];
c1.view.backgroundColor=[UIColor greenColor];
c1.tabBarItem.title=@"消息";
c1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
c1.tabBarItem.badgeValue=@"123";
UIViewController *c2=[[UIViewController alloc]init];
c2.view.backgroundColor=[UIColor brownColor];
c2.tabBarItem.title=@"联系人";
c2.tabBarItem.image=[UIImage imageNamed:@"tab_buddy_nor"];
UIViewController *c3=[[UIViewController alloc]init];
c3.tabBarItem.title=@"动态";
c3.tabBarItem.image=[UIImage imageNamed:@"tab_qworld_nor"];
UIViewController *c4=[[UIViewController alloc]init];
c4.tabBarItem.title=@"设置";
c4.tabBarItem.image=[UIImage imageNamed:@"tab_me_nor"];
//c.添加子控制器到ITabBarController中
//c.1第一种方式
[tb addChildViewController:c1];
[tb addChildViewController:c2];
//c.2第二种方式
tb.viewControllers=@[c1,c2,c3,c4];
//2.设置Window为主窗口并显示出来
[self.window makeKeyAndVisible];
return YES;
实现效果:
三、重要说明
1.UITabBar&
下方的工具条称为UITabBar ,如果UITabBarController有N个子控制器,那么UITabBar内部就会有N 个UITabBarButton作为子控件与之对应。
注意:UITabBarButton在UITabBar中得位置是均分的,UITabBar的高度为49。
在上面的程序中,UITabBarController有4个子控制器,所以UITabBar中有4个UITabBarButton,UITabBar的结构?大致如下图所示:
2.UITabBarButton&
UITabBarButton?面显?什么内容,由对应子控制器的tabBarItem属性来决定&
c1.tabBarItem.title=@"消息";
c1.tabBarItem.image=[UIImage imageNamed:@"tab_recent_nor"];
3.有两种方式可以往UITabBarController中添加子控制器&
(1)[tb addChildViewController:c1];
(2)tb.viewControllers=@[c1,c2,c3,c4];
注意:展示的顺序和添加的顺序一致,和导航控制器中不同,展现在眼前的是第一个添加的控制器对应的View。
随笔 - 179
评论 - 1450导航控制器//创建导航控制器BIDRootViewController *pRootVC=[[BIDRootViewController alloc]initWithNibName:nil bundle:nil];
self.mRootVC=pRootVC;
[pRootVC release]; UINavigationController *pNav=[[UINavigationController alloc]initWithRootViewController:self.mRootVC];
self.window.rootViewController=pN命名
self.navigationItem.title=@"根视图";给标题创建一个试图
UIView *pTitleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 160, 44)];
[pTitleView setBackgroundColor:[UIColor redColor]];
self.navigationItem.titleView=pTitleV创建一个barItemUIBarButtonItem *pBar=[[UIBarButtonItem alloc]initWithTitle:@"NextVC" style:UIBarButtonItemStylePlain target:self action:@selector(goToNextVC:)];
self.navigationItem.rightBarButtonItem=pBbarItem调用的方法- (void)goToNextVC:(id)sender{
BIDNextViewController *pNextVC=[[BIDNextViewController alloc]initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:pNextVC animated:YES];}tableBar―--标签栏创建标签栏BIDViewController *pViewController = [[BIDViewController alloc]initWithNibName:nil bundle:nil];
UITabBarController *pTapBarVC = [[UITabBarController alloc]init];
pTapBarVC.viewControllers=[NSArray arrayWithObjects:pViewController, nil];用系统的资源给标签命名
self.window.rootViewController = pTapBarVC;
self.tabBarItem=[[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:111];在右上角添加badgeValue
";自定义命名
self.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"second" image:nil tag:122];表视图创建.h文件中要有:@property (retain, nonatomic) UITableView *mTableV//存储表中的数据@property (retain, nonatomic) NSArray *mA且遵循UITableViewDataSource,UITableViewDelegate协议。
self.mArr = [UIFont familyNames];//创建初始化表视图
self.mTableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
UIView *pView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 50)];
pView.backgroundColor = [UIColor blueColor];
self.mTableView.tableHeaderView = pV
//设置页眉高度
self.mTableView.sectionHeaderHeight = 50;
//设置委托对象
self.mTableView.dataSource =
self.mTableView.delegate =
//加到视图当中
[self.view addSubview:self.mTableView];
#pragma mark --- tableView
DataSource----//每个分段中的行数- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.mArr count];}//每行的绘制- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifer = @"identfier";
UITableViewCell *pCell = [tableView dequeueReusableCellWithIdentifier:identifer];
if (nil == pCell)
pCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:identifer];
//获取当前行
NSUInteger cellRow = [indexPath row];
//根据行数找到数组中对应下标的数据
NSString *pTempStr = [self.mArr objectAtIndex:cellRow];
//设置文本内容
pCell.textLabel.text = pTempS
//设置文本字体
pCell.textLabel.font = [UIFont fontWithName:pTempStr size:18];
pCell.detailTextLabel.text = @“detailText";//在左侧添加图片
pCell.imageView.image = [UIImage imageNamed:@""];
pCell.accessoryType = UITableViewCellAccessoryC
return pC}//创建表头- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
return @"I'm Header_Title";}//创建表尾- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
return @"I'm Footer_Title";}#pragma mark---table delegate-----//选中某一行会调用- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
NSUInteger row = [indexPath row];
NSString *pStr = [NSString stringWithFormat:@"你选中了第%d行",row];
//模态视图
UIActionSheet *pActionSheet = [[UIActionSheet alloc]initWithTitle:@"ActionSheet" delegate:self cancelButtonTitle:@"确认" destructiveButtonTitle:pStr otherButtonTitles:nil, nil];
[pActionSheet showInView:self.view];
//选中行逐渐淡出
[self.mTableView deselectRowAtIndexPath:indexPath animated:YES];}//调整行高- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;}//调整header 高度- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 20;}//行内容进行偏移- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
return 0;}
最新教程周点击榜
微信扫一扫详谈隐藏Tabbar的几种方法 - 推酷
详谈隐藏Tabbar的几种方法
现在正在写的一个项目,涉及到了使用两个TabBar,然后我需要显示其中一个的时候,然后隐藏另外一个,但是中间却出现问题了.我查了一些资料,想总结一下关于TabBar的隐藏.
第一种方法是:
hidesBottomBarWhenPushed
这个方法是UIViewController的属性,很好用.但是我需要把隐藏的TabBar显示出来的时候,却发现显示不出来.
)viewWillAppear:(
hidesBottomBarWhenPushed
显示导航条
navigationController
navigationBarHidden
然后,我开始想,有没有其它的方法,我找了一下,发现了第二种方法;
第二种方法:
tabBarController
这个方法才是UITabBarController 自带的方法 ,我写了一下,发现能够隐藏.
然后,我赶紧试一下,是不是可以显示出来.
)viewWillAppear:(
tabBarController
显示导航条
navigationController
navigationBarHidden
我发现特别管用,我的TabBar显示出来了.我的问题,也解决了.所以,建议大家用第二种方法.
当然,在我查资料中,我也看到网友们提到的第三种方法;
第三种方法 :
就是把UITabBar的位置移动,即调整frame.origin.y的值。消失就是把它移出屏幕,出现就是把它再放回原地。(但,还原时又卡顿现象,体验很差,不建议)
所以,在ViewController7.m中:
//增加一个试图即将出现时的方法,并在此设置把tabBar下移,移除整个屏幕,相当于消失了
-(void)viewDidAppear:(BOOL)animated{
NSArray *arr1=self.tabBarController.view.
UIView *view1=[arr1 objectAtIndex:0];
UITabBar *tabBarView1=[arr1 objectAtIndex:1];
//第一个视图就是全屏,不需要把高度撑满,所以可以不做任何设置
//view1.frame=CGRectMake(0, 0, 375, 667);
tabBarView1.frame=CGRectMake(0, 667, 375, 49);
在ViewController1.m中:
//增加一个viewDidAppear,把下移的tabBar再上移,相当于还原到原地
-(void)viewDidAppear:(BOOL)animated{
NSArray *arr2=self.tabBarController.view.
UITabBar *tabBarView2=[arr2 objectAtIndex:1];
tabBarView2.frame=CGRectMake(0, 618, 375, 49);
好吧,目前知道就是这些了,欢迎大家根据自己的需求,挑选合适的方法.
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致

我要回帖

更多关于 苹果买手机送耳机 的文章

 

随机推荐