【问题标题】:Separating multiple UILabels with a line IOS用一行IOS分隔多个UILabel
【发布时间】:2012-10-19 06:40:55
【问题描述】:

我想设计一个设置页面,在其中我必须在多个标签之间画线,最好的方法是什么,我用谷歌搜索,了解CGContextRef 方法。这是正确的方法吗,我需要在标签之间划一条线(连续)。我可以继续使用这种方法还是任何其他最好的方法。

【问题讨论】:

  • 为每个分隔线创建一个 1 像素高的 CALayer 并设置其背景颜色。
  • 你为什么不做一个 UITableView ?我认为正在使用“设置”页面 Grouped TableView :)
  • 看看这个 - stackoverflow.com/questions/7666863/uiview-bottom-border>
  • 使用 UITableView,在 UITableView 内部添加标签或者你可以使用另一个标签,每个标签之间的高度为 1px

标签: iphone ios cocoa-touch uilabel cgcontextref


【解决方案1】:

我已将基本视图设置为深色,并将标签添加为白色,我在两个标签之间设置了一条线间隙,它看起来像一条线。没有额外的工作:)

【讨论】:

    【解决方案2】:

    可能只是在标签之间添加 UIView 吗?像这样的:

    UILabel *topLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 20)];
    //Label settings
    [self addSubview:topLabel];
    [topLabel release];
    
    UIView *separator = [[UIView alloc] initWithFrame:CGRectMake(topLabel.frame.origin.x, CGRectGetMaxY(topLabel.frame), topLabel.frame.size.width, 2)];
    separator.backgroundColor = [UIColor blackColor];
    
    UILabel *bottomLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(separator.frame), 320, 20)];
    //Label settings
    [self addSubview:bottomLabel];
    [bottomLabel release];
    

    【讨论】:

      【解决方案3】:

      难道你不能创建一个自定义 UIView 类,其中包含一个 UILabel 和一个 UIView 作为这个自定义视图类的子视图吗?

      class CustomView : UIView
      {
          UIView *line;
          UILabel *label;
      }
      
      @property(nonatomic, retain) UIView *line;
      @property(nonatomic, retain) UILabel *label;
      

      对于 UIView 子视图,你可以告诉它使用父 UIView 的宽度。

      【讨论】:

        猜你喜欢
        • 2015-07-26
        • 2013-07-03
        • 1970-01-01
        • 2021-08-13
        • 1970-01-01
        • 1970-01-01
        • 2011-11-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多