Skip to content

Commit

Permalink
Added additional properties to header
Browse files Browse the repository at this point in the history
  • Loading branch information
TimOliver committed Oct 1, 2023
1 parent 02700ec commit 19083f0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
11 changes: 11 additions & 0 deletions TORoundedButton/TORoundedButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
/// this property to your own custom UIView subclass in order to more efficiently manage sizing and layout.
@property (nonatomic, strong, null_resettable) UIView *contentView;

/// The amount of inset padding between the content view and the edges of the button.
/// (Default value is 15 points inset from each edge).
@property (nonatomic, assign) UIEdgeInsets contentInset;

/// The text that is displayed in center of the button (Default is nil).
@property (nonatomic, copy, nullable) IBInspectable NSString *text;

Expand Down Expand Up @@ -90,6 +94,13 @@ IB_DESIGNABLE @interface TORoundedButton : UIControl
/// Create a new instance of a button with the provided view set as the hosting content view.
- (instancetype)initWithContentView:(__kindof UIView *)contentView;

/// Resizes the button to fit the bounding size of all of the subviews in `contentView`, plus content insetting.
/// If a custom view was provided as the content view, or if the content view only has one subview this will also be called on it.
- (void)sizeToFit;

/// Calculates and returns the appropriate minimum size this button needs to be to fit into the provided size.
- (CGSize)sizeThatFits:(CGSize)size;

@end

NS_ASSUME_NONNULL_END
Expand Down
3 changes: 3 additions & 0 deletions TORoundedButton/TORoundedButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ - (void)_roundedButtonCommonInit TOROUNDEDBUTTON_OBJC_DIRECT {
_tapAnimationDuration = (_tapAnimationDuration > FLT_EPSILON) ?: 0.4f;
_tappedButtonScale = (_tappedButtonScale > FLT_EPSILON) ?: 0.97f;
_tappedTintColorBrightnessOffset = !TO_ROUNDED_BUTTON_FLOAT_IS_ZERO(_tappedTintColorBrightnessOffset) ?: -0.15f;
_contentInset = (UIEdgeInsets){15.0, 15.0, 15.0, 15.0};

// Set the tapped tint color if we've set to dynamically calculate it
[self _updateTappedTintColorForTintColor];
Expand Down Expand Up @@ -348,6 +349,7 @@ - (void)setContentView:(UIView *)contentView {
}

- (void)setAttributedText:(NSAttributedString *)attributedText {
[self _makeTitleLabelIfNeeded];
_titleLabel.attributedText = attributedText;
[_titleLabel sizeToFit];
[self setNeedsLayout];
Expand All @@ -356,6 +358,7 @@ - (void)setAttributedText:(NSAttributedString *)attributedText {
- (NSAttributedString *)attributedText { return _titleLabel.attributedText; }

- (void)setText:(NSString *)text {
[self _makeTitleLabelIfNeeded];
_titleLabel.text = text;
[_titleLabel sizeToFit];
[self setNeedsLayout];
Expand Down
8 changes: 4 additions & 4 deletions TORoundedButtonExample/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="18122" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="GV4-PL-MlK">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="22154" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="GV4-PL-MlK">
<device id="retina5_5" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="18093"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="22130"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
Expand All @@ -18,7 +18,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="3Rx-9D-Udo" userLabel="RoundedButton" customClass="TORoundedButton">
<rect key="frame" x="67" y="343" width="280" height="50"/>
<rect key="frame" x="67" y="353" width="280" height="50"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstAttribute="width" constant="280" id="OXU-dJ-PiL"/>
Expand All @@ -29,7 +29,7 @@
</userDefinedRuntimeAttributes>
</view>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Tapped!" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="YuK-c8-gCA">
<rect key="frame" x="159.66666666666666" y="166.66666666666666" width="94.666666666666657" height="35"/>
<rect key="frame" x="159.66666666666666" y="171.66666666666666" width="94.666666666666657" height="35"/>
<constraints>
<constraint firstAttribute="height" constant="35" id="A2b-ZQ-Mpt"/>
</constraints>
Expand Down

0 comments on commit 19083f0

Please sign in to comment.