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

  • <small id='YiLIX'></small><noframes id='YiLIX'>

      <bdo id='YiLIX'></bdo><ul id='YiLIX'></ul>

    <tfoot id='YiLIX'></tfoot>
      1. <legend id='YiLIX'><style id='YiLIX'><dir id='YiLIX'><q id='YiLIX'></q></dir></style></legend>
      2. 如何在 UIButton 上仅添加 TOP 边框?

        How to add only a TOP border on a UIButton?(如何在 UIButton 上仅添加 TOP 边框?)

          • <bdo id='EuL8J'></bdo><ul id='EuL8J'></ul>
              <legend id='EuL8J'><style id='EuL8J'><dir id='EuL8J'><q id='EuL8J'></q></dir></style></legend>
            • <tfoot id='EuL8J'></tfoot>

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

                  <tbody id='EuL8J'></tbody>

                  <i id='EuL8J'><tr id='EuL8J'><dt id='EuL8J'><q id='EuL8J'><span id='EuL8J'><b id='EuL8J'><form id='EuL8J'><ins id='EuL8J'></ins><ul id='EuL8J'></ul><sub id='EuL8J'></sub></form><legend id='EuL8J'></legend><bdo id='EuL8J'><pre id='EuL8J'><center id='EuL8J'></center></pre></bdo></b><th id='EuL8J'></th></span></q></dt></tr></i><div id='EuL8J'><tfoot id='EuL8J'></tfoot><dl id='EuL8J'><fieldset id='EuL8J'></fieldset></dl></div>
                1. 本文介绍了如何在 UIButton 上仅添加 TOP 边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我知道如何在 iOS 7 中为按钮添加边框,代码如下:

                  I know how to add border to a button in iOS 7, with the following code :

                  [[myButton layer] setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]];
                  [[myButton layer] setBorderWidth:1];
                  [[myButton layer] setCornerRadius:15];
                  

                  但是我怎样才能只添加一个边框呢?我只想添加顶部边框.

                  But how can I add just one border ? I want to add only the top border.

                  推荐答案

                  UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, btn.frame.size.width, 1)];
                  lineView.backgroundColor = [UIColor redColor];
                  [btn addSubview:lineView];
                  

                  您可以对每个边框执行相同的操作.添加多个 UIView,您可以添加底部和左侧或顶部和右侧或任何您想要的边框.

                  you can do the same for each border. Adding multiple UIViews you can add bottom and left or top and right or any border you want.

                  即底部&左:

                  UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, btn.frame.size.height - 1.0f, btn.frame.size.width, 1)];
                  bottomBorder.backgroundColor = [UIColor redColor];
                  
                  UIView *leftBorder = [[UIView alloc] initWithFrame:CGRectMake(1, 0, 1, btn.frame.size.height)];
                  leftBorder.backgroundColor = [UIColor redColor];
                  
                  [btn addSubview:bottomBorder];
                  [btn addSubview:leftBorder];
                  

                  如果你不使用 ARC,记得在添加子视图后释放 UIViews(或使用自动释放).

                  if you don't use ARC, remember to release UIViews after adding subviews (or use autorelease).

                  这篇关于如何在 UIButton 上仅添加 TOP 边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 标题颜色?)
                  Minimum sensible button size on iPhone(iPhone 上的最小合理按钮大小)
                  iPhone UIButton - image position(iPhone UIButton - 图像位置)
                  • <legend id='zZ8vh'><style id='zZ8vh'><dir id='zZ8vh'><q id='zZ8vh'></q></dir></style></legend>

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

                        <tbody id='zZ8vh'></tbody>

                      <tfoot id='zZ8vh'></tfoot>
                          <bdo id='zZ8vh'></bdo><ul id='zZ8vh'></ul>

                        • <i id='zZ8vh'><tr id='zZ8vh'><dt id='zZ8vh'><q id='zZ8vh'><span id='zZ8vh'><b id='zZ8vh'><form id='zZ8vh'><ins id='zZ8vh'></ins><ul id='zZ8vh'></ul><sub id='zZ8vh'></sub></form><legend id='zZ8vh'></legend><bdo id='zZ8vh'><pre id='zZ8vh'><center id='zZ8vh'></center></pre></bdo></b><th id='zZ8vh'></th></span></q></dt></tr></i><div id='zZ8vh'><tfoot id='zZ8vh'></tfoot><dl id='zZ8vh'><fieldset id='zZ8vh'></fieldset></dl></div>