Skip to content

Commit

Permalink
Merge pull request DavydLiu#137 from melinho/master
Browse files Browse the repository at this point in the history
Element should be align to right in right to left languages.
  • Loading branch information
DavydLiu authored Nov 29, 2018
2 parents c910ade + 8799e3b commit 9a1ad3d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions DLRadioButton/DLRadioButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ - (void)drawButton {
BOOL isRightToLeftLayout = NO;
if (@available(iOS 9.0, *)) {
isRightToLeftLayout = [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:self.semanticContentAttribute] == UIUserInterfaceLayoutDirectionRightToLeft;
if(isRightToLeftLayout){
self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
}
}
if (self.isIconOnRight) {
self.imageEdgeInsets = isRightToLeftLayout ?
Expand All @@ -110,12 +113,12 @@ - (UIImage *)drawIconWithSelection:(BOOL)selected {
CGFloat iconSize = self.iconSize;
CGFloat iconStrokeWidth = self.iconStrokeWidth ? self.iconStrokeWidth : iconSize / 9;
CGFloat indicatorSize = self.indicatorSize ? self.indicatorSize : iconSize * 0.5;

CGRect rect = CGRectMake(0, 0, iconSize, iconSize);
CGContextRef context = UIGraphicsGetCurrentContext();
UIGraphicsPushContext(context);
UIGraphicsBeginImageContextWithOptions(rect.size, NO, 0.0);

// draw icon
UIBezierPath* iconPath;
CGRect iconRect = CGRectMake(iconStrokeWidth / 2, iconStrokeWidth / 2, iconSize - iconStrokeWidth, iconSize - iconStrokeWidth);
Expand All @@ -128,7 +131,7 @@ - (UIImage *)drawIconWithSelection:(BOOL)selected {
iconPath.lineWidth = iconStrokeWidth;
[iconPath stroke];
CGContextAddPath(context, iconPath.CGPath);

// draw indicator
if (selected) {
UIBezierPath* indicatorPath;
Expand All @@ -142,11 +145,11 @@ - (UIImage *)drawIconWithSelection:(BOOL)selected {
[indicatorPath fill];
CGContextAddPath(context, indicatorPath.CGPath);
}

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsPopContext();
UIGraphicsEndImageContext();

image.accessibilityIdentifier = kGeneratedIconName;
return image;
}
Expand Down Expand Up @@ -231,7 +234,7 @@ - (UIColor *)titleColorForState:(UIControlState)state {
}
[self setTitleColor:selectedOrHighlightedColor forState:UIControlStateSelected | UIControlStateHighlighted];
}

return [super titleColorForState:state];
}

Expand All @@ -249,7 +252,7 @@ - (void)setSelected:(BOOL)selected {
animation.toValue = self.isSelected ? (id)self.icon.CGImage : (id)self.iconSelected.CGImage;
[self.imageView.layer addAnimation:animation forKey:@"icon"];
}

[super setSelected:selected];
if (!self.isMultipleSelectionEnabled && selected) {
[self deselectOtherButtons];
Expand Down

0 comments on commit 9a1ad3d

Please sign in to comment.