Home  >  Q&A  >  body text

ios - 初学,请问当我处理多个label的时候能不能统一处理宽高,不用每次去指定rect?

能不能像css那样对多个相似的组合统一处理。。 包括字体大小啊,样式啊

不知道ios里面可有方便的方法处理这种场景?

P.S:

好比css里能为一组元素设置一个class,然后给这种标识为该class的元素指定字体大小,颜色, 而ios里是怎么做到的?

ringa_leeringa_lee2764 days ago449

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 11:44:37

    Inherit. . . Inherit UILabel and set the format in the initialization method

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 11:44:37

    Can use macro #define

    reply
    0
  • PHPz

    PHPz2017-04-17 11:44:37

    You can use the same tag to get it and then set it uniformly

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:44:37

    You can use factory methods to set the same properties when creating. For different style classes, create different factory classes or modify methods.

    In addition, I have written a CSS-like viewCreater, which can be customized and set. If you are interested, you can take a look.

    // style.css UIView{background-color:black;width:240px; height:32px;} .testStyle{border-width:1px;border-color:white;border-radius:5px;}

    // demo.m UIView *widget = [UIView viewWithSelector:@".testStyle"];

    You will get a view with a black background, 240 pixels wide, 32 pixels high, and a 1 pixel wide rounded corner.

    https://github.com/rarexray/iOS_ViewCreatorWithStyle

    reply
    0
  • Cancelreply