Skip to content

Instantly share code, notes, and snippets.

@NSExceptional
Last active June 21, 2022 18:06
Show Gist options
  • Save NSExceptional/1c641e3a371a58db27ed0a2b2af7df6a to your computer and use it in GitHub Desktop.
Save NSExceptional/1c641e3a371a58db27ed0a2b2af7df6a to your computer and use it in GitHub Desktop.
Vote Control
#import "VoteControl.h"
@interface _VoteControl : UIStepper @end
@implementation _VoteControl
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.wraps = YES;
self.continuous = NO;
[self setDecrementImage:[UIImage systemImageNamed:@"arrow.left"] forState:UIControlStateNormal];
[self setIncrementImage:[UIImage systemImageNamed:@"arrow.right"] forState:UIControlStateNormal];
self.translatesAutoresizingMaskIntoConstraints = NO;
self.transform = CGAffineTransformRotate(self.transform, M_PI_2);
// self.backgroundColor = UIColor.blueColor;
}
return self;
}
@end
@interface VoteControl ()
@property (nonatomic, readonly) _VoteControl *control;
@end
@implementation VoteControl
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
_control = [_VoteControl new];
[self addSubview:_control];
// self.backgroundColor = UIColor.greenColor;
[NSLayoutConstraint activateConstraints:@[
[_control.centerXAnchor constraintEqualToAnchor:self.centerXAnchor],
[_control.centerYAnchor constraintEqualToAnchor:self.centerYAnchor],
[self.widthAnchor constraintEqualToAnchor:_control.heightAnchor],
[self.heightAnchor constraintEqualToAnchor:_control.widthAnchor],
]];
}
return self;
}
@end
@NSExceptional
Copy link
Author

Thanks /u/flying-insect!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment