1// 2// KBPrefButton.m 3// Keybase 4// 5// Created by Gabriel on 4/7/15. 6// Copyright (c) 2015 Gabriel Handford. All rights reserved. 7// 8 9#import "KBPrefButton.h" 10#import <Tikppa/Tikppa.h> 11 12@interface KBPrefButton () 13@property KBLabel *categoryLabel; // Optional 14@property KBButton *button; 15@property id<KBPreferences> preferences; 16@end 17 18@implementation KBPrefButton 19 20- (void)viewInit { 21 [super viewInit]; 22 _inset = 140; 23 24 _categoryLabel = [[KBLabel alloc] init]; 25 [self addSubview:_categoryLabel]; 26 27 _button = [KBButton button]; 28 [self addSubview:_button]; 29 30 YOSelf yself = self; 31 self.viewLayout = [YOLayout layoutWithLayoutBlock:^CGSize(id<YOLayout> layout, CGSize size) { 32 CGFloat x = 0; 33 CGFloat y = 0; 34 x += [layout sizeToFitVerticalInFrame:CGRectMake(x, y + 5, yself.inset, 0) view:yself.categoryLabel].size.width + 10; 35 36 y += [layout sizeToFitInFrame:CGRectMake(x, y, size.width - x, 0) view:yself.button].size.height; 37 return CGSizeMake(size.width, y); 38 }]; 39} 40 41- (void)setCategory:(NSString *)category { 42 [_categoryLabel setText:category style:KBTextStyleDefault alignment:NSRightTextAlignment lineBreakMode:NSLineBreakByClipping]; 43} 44 45- (void)setButtonText:(NSString *)buttonText targetBlock:(dispatch_block_t)targetBlock { 46 [_button setText:buttonText style:KBButtonStyleDefault options:KBButtonOptionsToolbar alignment:NSCenterTextAlignment lineBreakMode:NSLineBreakByClipping]; 47 _button.targetBlock = targetBlock; 48 [self setNeedsLayout]; 49} 50 51@end 52