如何从UILabel中删除UIAppearance设置?

时间:2017-07-14 03:09:49

标签: ios objective-c uiappearance

如何删除UILabel中已设置的UIAppearance设置?
或者我如何更新已经设置的UIAppearance?

我创建了一个自定义的UILabel方法,如下所示。

标题

- (void)setAppearanceFont:(UIFont *)font UI_APPEARANCE_SELECTOR;

实施

- (void)setAppearanceFont:(UIFont *)font
{
    _invokeCount += 1;

    NSLog(@"invokeCount: %ld", _invokeCount);
    self.font = font;
}

如果我设置了两次外观,则调用setAppearanceFont方法两次。

// set appearance
[[MyAppearanceLabel appearance] setAppearanceFont:font];
....
....
// set appearance from another timing
[[MyAppearanceLabel appearance] setAppearanceFont:font];

// show label
MyAppearanceLabel label* = [[MyAppearanceLabel alloc] 
                               initWithFrame:CGRectMake(0, 0, 100, 100)];
[self.view addSubview:label]; // <= invoked twice here!!

我想确保只调用一次setAppearance方法。

1 个答案:

答案 0 :(得分:1)

在swift 4中,我按照以下步骤进行操作(仅设置为零):

add_filter( 'gform_pre_render_2', 'my_populate_checkbox' );
function my_populate_checkbox( $form ) {

  foreach( $form['fields'] as &$field ) {

    if( 11 === $field->id ) {

      foreach( $field->choices as &$choice ) {

        $addons = get_field('addons');

        if( $addons === $choice['value'] ) {
          $choice['isSelected'] = true;
        }
      } 
    } 
  } 

  return $form;
}