<bdo id='cxG2r'></bdo><ul id='cxG2r'></ul>
<legend id='cxG2r'><style id='cxG2r'><dir id='cxG2r'><q id='cxG2r'></q></dir></style></legend>
<tfoot id='cxG2r'></tfoot>
    1. <i id='cxG2r'><tr id='cxG2r'><dt id='cxG2r'><q id='cxG2r'><span id='cxG2r'><b id='cxG2r'><form id='cxG2r'><ins id='cxG2r'></ins><ul id='cxG2r'></ul><sub id='cxG2r'></sub></form><legend id='cxG2r'></legend><bdo id='cxG2r'><pre id='cxG2r'><center id='cxG2r'></center></pre></bdo></b><th id='cxG2r'></th></span></q></dt></tr></i><div id='cxG2r'><tfoot id='cxG2r'></tfoot><dl id='cxG2r'><fieldset id='cxG2r'></fieldset></dl></div>

      1. <small id='cxG2r'></small><noframes id='cxG2r'>

        带有圆角和阴影的 UIBarButtonItem

        UIBarButtonItem with rounded corners and shadow(带有圆角和阴影的 UIBarButtonItem)
          <bdo id='TYHEA'></bdo><ul id='TYHEA'></ul>
          • <tfoot id='TYHEA'></tfoot><legend id='TYHEA'><style id='TYHEA'><dir id='TYHEA'><q id='TYHEA'></q></dir></style></legend>
            <i id='TYHEA'><tr id='TYHEA'><dt id='TYHEA'><q id='TYHEA'><span id='TYHEA'><b id='TYHEA'><form id='TYHEA'><ins id='TYHEA'></ins><ul id='TYHEA'></ul><sub id='TYHEA'></sub></form><legend id='TYHEA'></legend><bdo id='TYHEA'><pre id='TYHEA'><center id='TYHEA'></center></pre></bdo></b><th id='TYHEA'></th></span></q></dt></tr></i><div id='TYHEA'><tfoot id='TYHEA'></tfoot><dl id='TYHEA'><fieldset id='TYHEA'></fieldset></dl></div>

                  <tbody id='TYHEA'></tbody>

                  <small id='TYHEA'></small><noframes id='TYHEA'>

                1. 本文介绍了带有圆角和阴影的 UIBarButtonItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 UIBarButtonItem 上有圆角和阴影.

                  I want to have rounded corners and shadow on a UIBarButtonItem.

                  UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
                  

                  然后我尝试设置阴影和圆角:

                  Then I try to set shadow and rounded corners:

                  useButton.layer.masksToBounds = NO;
                  useButton.layer.cornerRadius = 4;
                  useButton.layer.shadowOffset = CGSizeMake(0, 1.5);
                  useButton.layer.shadowRadius = 0.5;
                  useButton.layer.shadowOpacity = 1.0;
                  useButton.layer.shadowColor = [BSTCMColorUtility colorFromHexString:@"#AFAFAF"].CGColor;
                  

                  最后我制作了 UIBarButtonItem:

                  UIBarButtonItem *useItem = [[UIBarButtonItem alloc] initWithCustomView:useButton];
                  [self.navigationItem setRightBarButtonItems:@[useItem]];
                  

                  没有圆角,但有阴影.

                  如果我添加:

                  useButton.clipsToBounds = YES;
                  

                  和/或:

                  useButton.layer.masksToBounds = YES;
                  

                  我得到圆角,但没有阴影.所以我想我会尝试添加一个子层.

                  I get rounded corners, but no shadow. So I thought that I would try to add a sublayer.

                  CALayer *useButtonShadowLayer = [CALayer new];
                  useButtonShadowLayer.frame = useButton.frame;
                  useButtonShadowLayer.cornerRadius = 4;
                  useButtonShadowLayer.backgroundColor = [UIColor whiteColor].CGColor;
                  useButtonShadowLayer.shadowOffset = CGSizeMake(0, 1.5);
                  useButtonShadowLayer.shadowRadius = 0.5;
                  useButtonShadowLayer.shadowOpacity = 1.0;
                  useButtonShadowLayer.shadowColor = [BSTCMColorUtility colorFromHexString:@"#AFAFAF"].CGColor;
                  
                  useButton.layer.cornerRadius = 4;
                  useButton.layer.masksToBounds = YES;
                  
                  UIView *parent = useButton.superview;
                  [parent.layer insertSublayer:useButtonShadowLayer below:useButton.layer];
                  

                  它似乎不起作用,我看不到阴影.我得到了圆角.

                  It doesn't seem to work, I see no shadow. I get rounded corners tho.

                  UIBarButtonItem/UIButton 上不可能有圆角和阴影吗?

                  Isn't possible to have rounded corners AND shadow on a UIBarButtonItem/UIButton?

                  推荐答案

                  试试这个更新的代码:

                  UIButton *useButton = [UIButton buttonWithType:UIButtonTypeCustom];
                  useButton.frame = CGRectMake(100, 430, 100, 40);
                  useButton.layer.masksToBounds = NO;
                  useButton.layer.cornerRadius = 10;
                  useButton.layer.shadowOffset = CGSizeMake(1.5, 1.5);
                  useButton.layer.shadowRadius = 0.5;
                  useButton.layer.shadowOpacity = 1.0;
                  useButton.layer.shadowColor = [UIColor blackColor].CGColor;
                  useButton.backgroundColor = [UIColor redColor];
                  
                  UIBarButtonItem *useItem = [[UIBarButtonItem alloc] initWithCustomView:useButton];
                  [self.navigationItem setRightBarButtonItems:@[useItem]];
                  

                  这篇关于带有圆角和阴影的 UIBarButtonItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  UIButton title text color(UIButton 标题文本颜色)
                  Stretch background image for UIButton(为 UIButton 拉伸背景图像)
                  Using Tint color on UIImageView(在 UIImageView 上使用 Tint 颜色)
                  How can I change UIButton title color?(如何更改 UIButton 标题颜色?)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  UIButton remove all target-actions(UIButton 删除所有目标动作)
                2. <i id='KFGCw'><tr id='KFGCw'><dt id='KFGCw'><q id='KFGCw'><span id='KFGCw'><b id='KFGCw'><form id='KFGCw'><ins id='KFGCw'></ins><ul id='KFGCw'></ul><sub id='KFGCw'></sub></form><legend id='KFGCw'></legend><bdo id='KFGCw'><pre id='KFGCw'><center id='KFGCw'></center></pre></bdo></b><th id='KFGCw'></th></span></q></dt></tr></i><div id='KFGCw'><tfoot id='KFGCw'></tfoot><dl id='KFGCw'><fieldset id='KFGCw'></fieldset></dl></div>
                      <bdo id='KFGCw'></bdo><ul id='KFGCw'></ul>
                          <tfoot id='KFGCw'></tfoot>
                        1. <small id='KFGCw'></small><noframes id='KFGCw'>

                          <legend id='KFGCw'><style id='KFGCw'><dir id='KFGCw'><q id='KFGCw'></q></dir></style></legend>
                              <tbody id='KFGCw'></tbody>