iOS : How to add Underline in UITabBarItem

后端 未结 5 1516
情书的邮戳
情书的邮戳 2021-02-09 14:36

I am working in a application where i need to add underline in UITabbarItem.

so i would like to add underline under the selected UITabbarItem i

5条回答
  •  情歌与酒
    2021-02-09 14:38

    Just Place this code into Appdelegate.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    UIView *view1 = [[UIView alloc]initWithFrame:CGRectMake([UITabBar appearance].frame.origin.x,[UITabBar appearance].frame.origin.y, [[UIScreen mainScreen] bounds].size.width/3, 56)];
    
    UIImageView *border = [[UIImageView alloc]initWithFrame:CGRectMake(view1.frame.origin.x,view1.frame.size.height-6, [[UIScreen mainScreen] bounds].size.width/3, 6)];
    border.backgroundColor = [UIColor colorWithRed:255.0f/255.0f green:105.0f/255.0f blue:84.0f/255.0f alpha:1.0f];
    [view1 addSubview:border];
    UIImage *img=[self ChangeViewToImage:view1];
    [[UITabBar appearance] setSelectionIndicatorImage:img];
    [[UITabBar appearance] setTintColor: [UIColor colorWithRed:255.0f/255.0f green:105.0f/255.0f blue:84.0f/255.0f alpha:1.0f]];
    
    return YES;
    }
    -(UIImage * ) ChangeViewToImage : (UIView *) viewForImage
    {
    UIGraphicsBeginImageContext(viewForImage.bounds.size);
    [viewForImage.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
    }
    

提交回复
热议问题