ios 怎么将uitabbar设置ios 文字垂直滚动

UITabBar 外观 setSelectionIndicatorImage 不工作第一次发射 iOS7
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.
我有定制的 UITabBar,并在 AppDelegate 中使用以下代码:
- (void)tabBarController:(MainUITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[self customizeTabBar];
- (void)customizeTabBar {
NSLog(@"*******customizeTabBar*******");
UIImage *tabBackground = [[UIImage imageNamed:@"unselectedtab"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
// Set background for all UITabBars
[[UITabBar appearance] setBackgroundImage:tabBackground];
// Set tint color for the images for all tabbars
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
// Set selectionIndicatorImage for all tabbars
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selectedtab"]];
- (void)tabBarController:(MainUITabBarController *)tabBarController didEndCustomizingViewControllers:(NSArray *)viewControllers changed:(BOOL)changed
NSLog(@"*******didEndCustomizingViewControllers*******");
这是一切都很美好 iOS5 +,但在第一次加载 7 第 TabBarItem 项指标是白色和按钮似乎已被选定但是"selectedTab"图像不能加载。
当我按下另一个选项卡新选项卡是红的正确-显示一样,第一次或任何在此-之后选定的选项卡栏项目只没用第一次发射。
customizeTabBar 会被调用,但所选的图像未出现在第一次发射。
didEndCustomizingViewControllers 似乎并不会在所有被调用。
这在模拟器或设备上 iOS7-中不工作,但在 iOS5,6。
有什么想法?先谢谢了。
解决方法 1:
除了做它的外观,通过直接再次设置为选项卡栏的选择指示器图像为我工作!
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UITabBarController *tabBarContr = (UITabBarController *)self.window.rootViewC
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_bar_selection_indicator.png"]];
// iOS7 hack: to make selectionIndicatorImage appear on the selected tab on the first app run
[[tabBarContr tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_bar_selection_indicator.png"]];
return YES;在storyboard,选中TabBar item,设置即可
已有帐号?
无法登录?
社交帐号登录
Let's warp the time.iOS自定义UITabBar
push页面时,可调用hidesBottomBarWhenPushed进行隐藏。
第一步,我们需要一些图片:
各个选项的图标和tabbar的背景图片,最后还要一个透明的1x1像素的图片。
第二步,新建一个工程,在工程内建一个继承于UITabBarController的类。
第三步,首先写一个方法,返回一个UINavigationController
-(UINavigationController*) viewControllerWithTitle:(NSString*) title image:(UIImage*)image
UIViewController* viewController = [[UIViewController alloc] init];
viewController.tabBarItem = [[UITabBarItem alloc] initWithTitle:title image:image tag:0];
viewController.title =
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:viewController];
然后在viewDidLoad里面创建TabbarController的viewControllers
self.viewControllers = [NSArray arrayWithObjects:
[self viewControllerWithTitle:@"1" image:IMG(@"1")],
[self viewControllerWithTitle:@"2" image:IMG(@"2")],
[self viewControllerWithTitle:nil image:nil],
[self viewControllerWithTitle:@"3" image:IMG(@"3")],
[self viewControllerWithTitle:@"4" image:IMG(@"4")], nil];
看到没有,比较猥琐的就是第三个ViewController什么都没设置。
因为我们要在那个位置放一个自己的按钮,继续在viewDidLoad写:
UIButton* button = [[UIButton alloc]initWithFrame:CGRectMake(0.0, 0.0, 65, 65)];
button.center = CGPointMake(160, 20);
[button setBackgroundImage:IMG(@"add") forState:UIControlStateNormal];
[button addTarget:self action:@selector(add:) forControlEvents:UIControlEventTouchUpInside];
[self.tabBar addSubview:button];
然后设置背景图片:
[self.tabBar setBackgroundImage:IMG(@"tabbarbg")];
运行之后是这样的:
会发现按钮上面有一条横线,然后再设置这个阴影运行后就没有人发现你猥琐的行径。
[self.tabBar setShadowImage:IMG(@"transparent")];最后效果图(iOS7和iOS6):
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
您的访问请求被拒绝 403 Forbidden - ITeye技术社区
您的访问请求被拒绝
亲爱的会员,您的IP地址所在网段被ITeye拒绝服务,这可能是以下两种情况导致:
一、您所在的网段内有网络爬虫大量抓取ITeye网页,为保证其他人流畅的访问ITeye,该网段被ITeye拒绝
二、您通过某个代理服务器访问ITeye网站,该代理服务器被网络爬虫利用,大量抓取ITeye网页
请您点击按钮解除封锁&iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
iOS 开发 中级:UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem自定义方法总结
& & & &对于UIToolbar,UINavigationBar,UITabBar,UIBarButtonItem,UITabBarItem这几种控件的自定义,因为具备共同性,因此放在一起讨论。
通常有两种方式来实现自定义。
1)获取控件的对象,然后对这个特定的对象进行特定的修改。
2)利用UIAppearance来实现对所有同类控件及特定同类的自定义。因为大多数应用里面的自定义为了美观,基本上相同类的控件自定义方式都一样,因此采用UIAppearance来使得界面的自定义变得非常方便。对于这种方式,通常在AppDelegate.m文件中实现,在
)application:(
UIApplication
*)application didFinishLaunchingWithOptions:(
NSDictionary
*)launchOptions 这个方法内实现。
这里介绍一下UIAppearance的使用,参考自“UIAppearance protocol reference",有两种方式:
1、自定义所有类对象的显示。
[[UINavigationBar appearance] setTintColor:myColor];
2、自定义包含在特定containerclass 的类对象的显示。这主要针对UIBarButtonItem,就是说有的UIBarButtonItem在UINavigationBar中,有的在UIToolbar中,我们可以选择性的对存在于哪个bar中的button进行自定义。举例如下:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]setTintColor:myNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class],[UIPopoverController class], nil] setTintColor:myPopoverNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setTintColor:myToolbarColor];
下面总结一下各控件使用UIAppearance自定义的Methods。摘自各苹果官方的Reference.注意下面的方法同样可以单独用于某个单独的对象。
1、UIToolbar
Customizing Appearance
– backgroundImageForToolbarPosition:barMetrics:
Returns the image to use for the background in a given position and with given metrics.
– setBackgroundImage:forToolbarPosition:barMetrics:
Sets the image to use for the background in a given position and with given metrics.
– shadowImageForToolbarPosition:
Returns the image to use for the toolbar shadow in a given position.
– setShadowImage:forToolbarPosition:
Sets the image to use for the toolbar shadow in a given position.&
The color used to tint the bar.&
2、UITabBar
Customizing Appearance
backgroundImage
The background image for the bar.
selectedImageTintColor
The tint color to apply to the gradient image used when creating the selected image.
selectionIndicatorImage
The image used for the selection indicator.
shadowImage
The shadow image to be used for the tab bar.
The tint color to apply to the tab bar background.&
3、UINavigationBar
Customizing the Bar Appearance
The color used to tint the bar.
–backgroundImageForBarMetrics:(page11)
Returns the background image for given bar metrics.
– &setBackgroundImage:forBarMetrics:
(page 13)Sets the background image for given bar metrics.
– &titleVerticalPositionAdjustmentForBarMetrics:
(page 14)Returns the title’s vertical position adjustment for given bar metrics.
– &setTitleVerticalPositionAdjustment:forBarMetrics:
(page 14)Sets the title’s vertical position adjustment for given bar metrics.
titleTextAttributes
Display attributes for the bar’s title text.&
4、UIBarButtonItem
Customizing Appearance
The tint color for the button item.
– &backButtonBackgroundImageForState:barMetrics:
Returns the back button background image for a given control state and bar metrics.
– &setBackButtonBackgroundImage:forState:barMetrics:
Sets the back button background image for a given control state and bar metrics
–backButtonTitlePositionAdjustmentForBarMetrics:(page11)
Returns the back button title offset for given bar metrics.
– setBackButtonTitlePositionAdjustment:forBarMetrics:
(page 19)Sets the back button title offset for given bar metrics
– backButtonBackgroundVerticalPositionAdjustmentForBarMetrics:
(page 10)Returns the back button vertical position offset for given bar metrics.
– setBackButtonBackgroundVerticalPositionAdjustment:forBarMetrics:
(page 18)Sets the back button vertical position offset for given bar metrics.
– backgroundVerticalPositionAdjustmentForBarMetrics:
(page 13)Returns the background vertical position offset for given bar metrics.
– setBackgroundVerticalPositionAdjustment:forBarMetrics:
(page 21)Sets the background vertical position offset for given bar metrics.
–backgroundImageForState:barMetrics:(page11)
Returns the background image for a given state and bar metrics.
– setBackgroundImage:forState:barMetrics:
Sets the background image for a given state and bar metrics.
– backgroundImageForState:style:barMetrics:
Returns the background image for the specified state, style, and metrics.
– setBackgroundImage:forState:style:barMetrics:
Sets the background image for the specified state, style, and metrics.
– titlePositionAdjustmentForBarMetrics:
(page 22)Returns the title offset for given bar metrics.
– setTitlePositionAdjustment:forBarMetrics:
(page 21)Sets the title offset for given bar metrics.&
5、UITabBarItem
Customizing Appearance
– titlePositionAdjustment
Returns the offset to use to adjust the title position.
– setTitlePositionAdjustment:
Sets the offset to use to adjust the title position.&
除此之外,就是针对特定对象进行的自定义了。
1、UITabBarItem
– finishedSelectedImage
(page 5)Returns the finished selected image.
– finishedUnselectedImage
(page 5)Returns the finished unselected image.
– setFinishedSelectedImage:withFinishedUnselectedImage:
(page 7)Sets the finished selected and unselected images.&
上面的方法用于更改每个单独的TabBarItem 选中及未选中的图像
2、UIBarButtonItem
The style of the item.
possibleTitles
The set of possible titles to display on the bar button.
The width of the item.
customView
A custom view representing the item.&
3、UINavigationBar
The appearance of the navigation bar.
shadowImage
The shadow image to be used for the navigation bar.
translucent
A Boolean value indicating whether the navigation bar is only partially opaque.&
基本上,把这些方法搞定,自定义就易如反掌了。
发表评论:
TA的最新馆藏

我要回帖

更多关于 ios uilabel 垂直居中 的文章

 

随机推荐