Monday, June 10, 2013

UITabBarItem titlePositionAdjustment example in Objective C (iOS).


UITabBarItem titlePositionAdjustment

Returns the offset to use to adjust the title position.

- (UIOffset)titlePositionAdjustment

Return Value of [UITabBarItem titlePositionAdjustment]
The offset to use to adjust the title position.

UITabBarItem titlePositionAdjustment example.
verticalOffset = UIOffset.new(0, -4)

self.tabBarItem = UITabBarItem.alloc.initWithTitle('First', image: nil, tag: 0)
self.tabBarItem.setFinishedSelectedImage(tabSelected, withFinishedUnselectedImage: tabNormal)
self.tabBarItem.setTitlePositionAdjustment(verticalOffset)

Example of [UITabBarItem titlePositionAdjustment].
UITabBar *tabBar = self.tabBarController.tabBar;

 UITabBarItem *item0 = [tabBar.items objectAtIndex:0];

 item0.titlePositionAdjustment = UIOffsetMake(10, 5);

UITabBarItem titlePositionAdjustment example.
 self.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:nil tag:0];
        [[self tabBarItem] setFinishedSelectedImage:[UIImage imageNamed:@"Home_icon"]
                        withFinishedUnselectedImage:[UIImage imageNamed:@"Home_icon_selected"]];
        // move text up
        self.tabBarItem.titlePositionAdjustment = UIOffsetMake(0.0, -4.0);
        // set color for text
        [[self tabBarItem] setTitleTextAttributes:@{
                         UITextAttributeTextColor:[UIColor colorWithRed:0.253 green:0.243 blue:0.226 alpha:1.000],
                              NSFontAttributeName:LCFontStyleNTabBarText}
                                         forState:UIControlStateNormal];
        [[self tabBarItem] setTitleTextAttributes:@{
                         UITextAttributeTextColor:[UIColor whiteColor],
                              NSFontAttributeName:LCFontStyleNTabBarText}
                                         forState:UIControlStateSelected];

End of UITabBarItem titlePositionAdjustment example article.