ios – 如何在UINavigationBar中水平放置backIndicatorImage

ios – 如何在UINavigationBar中水平放置backIndicatorImage,第1张

概述我使用此代码将insets添加到navigaiton栏的backIndicator图像.但是,这仅适用于图像的垂直定位. 我只能将图像向上或向下移动,但不能向左或向右移动. 看起来左/右插图不起作用.我不确定可能是什么问题. UIEdgeInsets insets = UIEdgeInsetsMake(0, 20, 0, 0); //(20,0,0,0) works fine UIImage * 我使用此代码将insets添加到navigaiton栏的backIndicator图像.但是,这仅适用于图像的垂直定位.
我只能将图像向上或向下移动,但不能向左或向右移动.
看起来左/右插图不起作用.我不确定可能是什么问题.

UIEdgeInsets insets = UIEdgeInsetsMake(0,20,0); //(20,0) works fine UIImage *backArrowImage = [[UIImage imagenamed:@"Back"] imageWithAlignmentRectInsets:insets]; [[UINavigationbar appearance] setBackIndicatorImage:backArrowImage]; [[UINavigationbar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];

我也试过这个:

UIImage * backArrowImage =[[UIImage imagenamed:@"Back"]resizableImageWithCAPInsets:UIEdgeInsetsMake(0,0) resizingMode:UIImageResizingModeStretch];

如果这不可能,我是否需要返回添加自定义后退按钮?

解决方法 我已经尝试了很多方法,最后这对我有用,你可以重绘你的照片,做如下:

UIImage *arrow = [UIImage imagenamed:@"Back_normal"];UIGraphicsBeginImageContextWithOptions(CGSizeMake(arrow.size.wIDth+10,arrow.size.height),NO,0); // move the pic by 10,change it to the num you want[arrow drawAtPoint:CGPointMake(10,0)];UIImage *finalimage = UIGraphicsGetimageFromCurrentimageContext();UIGraphicsEndImageContext();

然后使用finalimage作为backIndicatorImage.

总结

以上是内存溢出为你收集整理的ios – 如何在UINavigationBar中水平放置backIndicatorImage全部内容,希望文章能够帮你解决ios – 如何在UINavigationBar中水平放置backIndicatorImage所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1062177.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存