Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
/** The text that is displayed in center of the button (Default is "Button") */
@property (nonatomic, copy) IBInspectable NSString *text;

/** The Attributed string used in the label of this button (Default is nil) */
/** See UILabel `attributedText` property  documentation for full details. */
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;

/** The radius of the corners of this button (Default is 10.0f) */
@property (nonatomic, assign) IBInspectable CGFloat cornerRadius;

Expand Down
10 changes: 10 additions & 0 deletions TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,16 @@ - (void)setButtonScaledTappedAnimated:(BOOL)animated

#pragma mark - Public Accessors -

- (void)setAttributedText:(NSAttributedString *)attributedText
{
self.titleLabel.attributedText = attributedText;
}

- (NSAttributedString *)attributedText
{
return self.titleLabel.attributedText;
}

- (void)setText:(NSString *)text
{
self.titleLabel.text = text;
Expand Down
3 changes: 3 additions & 0 deletions TORoundedButtonExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<constraint firstAttribute="height" constant="50" id="LGv-FO-mLX"/>
<constraint firstAttribute="width" constant="288" id="hN0-R5-rZn"/>
</constraints>
<userDefinedRuntimeAttributes>
<userDefinedRuntimeAttribute type="string" keyPath="text" value="Plain Text"/>
</userDefinedRuntimeAttributes>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Opaque" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="l8T-Yp-FD5">
<rect key="frame" x="16" y="163" width="75" height="24"/>
Expand Down
4 changes: 4 additions & 0 deletions TORoundedButtonExample/ViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface NSAttributedString (TORoundedButton)
+ (NSAttributedString *)exampleString;
@end

NS_ASSUME_NONNULL_END
37 changes: 37 additions & 0 deletions TORoundedButtonExample/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ - (void)viewDidLoad {
self.opaqueTappedLabel.alpha = 0.0f;
self.transparentTappedLabel.alpha = 0.0f;

self.clearButton.attributedText = [NSAttributedString exampleString];

__weak typeof(self) weakSelf = self;
self.opaqueButton.tappedHandler = ^{
[weakSelf playFadeAnimationOnView:weakSelf.opaqueTappedLabel];
Expand All @@ -46,3 +48,38 @@ - (void)playFadeAnimationOnView:(UIView *)view
}

@end

@implementation NSAttributedString (TORoundedButton)

+ (NSAttributedString*)exampleString
{
NSMutableAttributedString *mutString = [NSMutableAttributedString new];
NSAttributedString *string1 = [[NSAttributedString alloc] initWithString:@"A" attributes:
@{
NSFontAttributeName : [UIFont fontWithName:@"Zapfino" size:22],
NSForegroundColorAttributeName : [UIColor whiteColor]
}];
[mutString appendAttributedString:string1];
NSAttributedString *string2 = [[NSAttributedString alloc] initWithString:@"tt" attributes:
@{
NSFontAttributeName : [UIFont fontWithName:@"Zapfino" size:17],
NSForegroundColorAttributeName : [UIColor orangeColor]
}];
[mutString appendAttributedString:string2];
NSAttributedString *string3 = [[NSAttributedString alloc] initWithString:@"ribu" attributes:
@{
NSFontAttributeName : [UIFont fontWithName:@"ChalkboardSE-Regular" size:16],
NSForegroundColorAttributeName : [UIColor yellowColor]
}];
[mutString appendAttributedString:string3];
NSAttributedString *string4 = [[NSAttributedString alloc] initWithString:@"ted" attributes:
@{
NSFontAttributeName : [UIFont fontWithName:@"Courier" size:22],
NSForegroundColorAttributeName : [UIColor greenColor]
}];
[mutString appendAttributedString:string4];

return [mutString copy];
}

@end