Skip to content
Open
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
58 changes: 31 additions & 27 deletions Classes/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9531" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="vXZ-lx-hvc">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9529"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--View Controller-->
Expand All @@ -14,62 +18,62 @@
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Index:" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="t7U-Ia-bLd">
<rect key="frame" x="16" y="485" width="41.5" height="18"/>
<rect key="frame" x="16" y="552" width="41.5" height="18"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.36767482757568359" green="0.36766383051872253" blue="0.36767005920410156" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<nil key="highlightedColor"/>
</label>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="0" borderStyle="roundedRect" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="Q33-2Y-lMM">
<rect key="frame" x="65" y="479" width="60" height="30"/>
<rect key="frame" x="65" y="546" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Uf7-fG-zZF"/>
</constraints>
<color key="textColor" red="0.44313725490196076" green="0.44313725490196076" blue="0.44313725490196076" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="textColor" red="0.36767482757568359" green="0.36766383051872253" blue="0.36767005920410156" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" keyboardType="numberPad"/>
</textField>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Be7-f3-ZyA">
<rect key="frame" x="16" y="530" width="60" height="30"/>
<rect key="frame" x="16" y="597" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="a9z-2k-Bwd"/>
</constraints>
<state key="normal" title="Add">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onAdd:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="CMN-TA-f6C"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="io1-TE-I9C">
<rect key="frame" x="270" y="530" width="60" height="30"/>
<rect key="frame" x="157.5" y="597" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="Kq2-EH-d4c"/>
</constraints>
<state key="normal" title="Insert">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onInsert:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="cIP-vB-HTP"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="hgs-nh-fvM">
<rect key="frame" x="520" y="530" width="60" height="30"/>
<rect key="frame" x="295" y="597" width="60" height="30"/>
<constraints>
<constraint firstAttribute="width" constant="60" id="MFl-wp-oDo"/>
</constraints>
<state key="normal" title="Remove">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
<color key="titleShadowColor" red="0.5" green="0.5" blue="0.5" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<connections>
<action selector="onRemove:" destination="vXZ-lx-hvc" eventType="touchUpInside" id="Ltg-iR-8bw"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.92941176469999998" green="0.92941176469999998" blue="0.92941176469999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color key="backgroundColor" red="0.91180288791656494" green="0.91177564859390259" blue="0.91179108619689941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<gestureRecognizers/>
<constraints>
<constraint firstItem="Q33-2Y-lMM" firstAttribute="leading" secondItem="t7U-Ia-bLd" secondAttribute="trailing" constant="7.5" id="9gj-3P-iRd"/>
Expand Down Expand Up @@ -105,25 +109,25 @@
<objects>
<tableViewController storyboardIdentifier="TagsTableViewController" id="FbG-4l-pGh" customClass="TagsTableViewController" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" id="Wr1-1i-w0o">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" red="0.92941176469999998" green="0.92941176469999998" blue="0.92941176469999998" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<view key="tableFooterView" contentMode="scaleToFill" id="4yZ-QU-cV5" userLabel="Footer">
<rect key="frame" x="0.0" y="130" width="600" height="0.0"/>
<color key="backgroundColor" red="0.91180288791656494" green="0.91177564859390259" blue="0.91179108619689941" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<view key="tableFooterView" contentMode="scaleToFill" misplaced="YES" id="4yZ-QU-cV5" userLabel="Footer">
<rect key="frame" x="0.0" y="66" width="375" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="0.0" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<prototypes>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="TagsTableCell" id="m3R-h8-kmN" customClass="TagsTableCell">
<rect key="frame" x="0.0" y="86" width="600" height="44"/>
<rect key="frame" x="0.0" y="22" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="m3R-h8-kmN" id="nn6-mE-tbH">
<rect key="frame" x="0.0" y="0.0" width="600" height="43.5"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="xsy-ND-UuT" customClass="SKTagView">
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
</subviews>
<constraints>
Expand Down Expand Up @@ -159,9 +163,9 @@
<viewControllerLayoutGuide type="bottom" id="ZfB-s6-959"/>
</layoutGuides>
<view key="view" contentMode="scaleToFill" id="LGE-qp-0iD">
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</view>
<navigationItem key="navigationItem" title="Detail" id="juj-Ko-kcc"/>
</viewController>
Expand All @@ -175,7 +179,7 @@
<navigationController storyboardIdentifier="TableNV" automaticallyAdjustsScrollViewInsets="NO" id="KA0-I5-dTs" sceneMemberID="viewController">
<toolbarItems/>
<navigationBar key="navigationBar" contentMode="scaleToFill" id="Q4L-7C-Az2">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<rect key="frame" x="0.0" y="20" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
</navigationBar>
<nil name="viewControllers"/>
Expand Down
15 changes: 15 additions & 0 deletions Classes/CustomTagButton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CustomTagButton.h
// SKTagView
//
// Created by zhangchong on 2018/1/17.
// Copyright © 2018年 shiweifu. All rights reserved.
//

#import "SKTagButton.h"

@interface CustomTagButton : SKTagButton

+ (nonnull instancetype)buttonWithTag: (nonnull SKTag *)tag;

@end
90 changes: 90 additions & 0 deletions Classes/CustomTagButton.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// CustomTagButton.m
// SKTagView
//
// Created by zhangchong on 2018/1/17.
// Copyright © 2018年 shiweifu. All rights reserved.
//

#import "CustomTagButton.h"
#import "SKTag.h"

static const CGFloat kLeftOffsetOfImageToTitle = 8.f;
static const CGFloat kLeftOffsetOfTitleToButton = 13.f;
static const CGFloat kRightOffsetOfTitleToButton = 35.f;

@implementation CustomTagButton

+ (nonnull instancetype)buttonWithTag: (nonnull SKTag *)tag {
CustomTagButton *btn = [super buttonWithType:UIButtonTypeCustom];

if (tag.attributedText) {
[btn setAttributedTitle: tag.attributedText forState: UIControlStateNormal];
} else {
[btn setTitle: tag.text forState:UIControlStateNormal];
[btn setImage: tag.image forState:UIControlStateNormal];
[btn setTitleColor: tag.textColor forState: UIControlStateNormal];
btn.titleLabel.font = tag.font ?: [UIFont systemFontOfSize: tag.fontSize];
}

btn.backgroundColor = tag.bgColor;
btn.contentEdgeInsets = tag.padding;
btn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;

if (tag.bgImg) {
[btn setBackgroundImage: tag.bgImg forState: UIControlStateNormal];
}

if (tag.borderColor) {
btn.layer.borderColor = tag.borderColor.CGColor;
}

if (tag.borderWidth) {
btn.layer.borderWidth = tag.borderWidth;
}

btn.userInteractionEnabled = tag.enable;
if (tag.enable) {
UIColor *highlightedBgColor = tag.highlightedBgColor ?: [self darkerColor:btn.backgroundColor];
[btn setBackgroundImage:[self imageWithColor:highlightedBgColor] forState:UIControlStateHighlighted];
}

btn.layer.cornerRadius = tag.cornerRadius;
btn.layer.masksToBounds = YES;

return btn;
}

- (void)layoutSubviews {
[super layoutSubviews];

if (self.imageView) {
// NSLog(@"imageEdgeInsets: %@", NSStringFromUIEdgeInsets(self.imageEdgeInsets));
// NSLog(@"titleEdgeInsets: %@", NSStringFromUIEdgeInsets(self.titleEdgeInsets));

self.imageEdgeInsets = UIEdgeInsetsMake(0, (self.titleLabel.frame.size.width + kLeftOffsetOfImageToTitle),
0, -(self.titleLabel.frame.size.width + kLeftOffsetOfImageToTitle));
self.titleEdgeInsets = UIEdgeInsetsMake(0, -(self.imageView.frame.size.width), 0,
self.imageView.frame.size.width);

}

NSLog(@"line:[%@] bounds:[%@] titleFrame:[%@] imageFrame:[%@]",
@(__LINE__),
NSStringFromCGRect(self.bounds),
NSStringFromCGRect(self.titleLabel.frame),
NSStringFromCGRect(self.imageView.frame));
}

- (CGSize)intrinsicContentSize {
CGSize titleSize = [self.titleLabel intrinsicContentSize];
CGSize imageSize = [self.imageView intrinsicContentSize];
NSLog(@"line:[%@] titleSize:[%@], imageSize:[%@]",
@(__LINE__),
NSStringFromCGSize(titleSize),
NSStringFromCGSize(imageSize));
CGSize size = CGSizeMake(kLeftOffsetOfTitleToButton + titleSize.width + kRightOffsetOfTitleToButton, 32);
return size;
}

@end
15 changes: 15 additions & 0 deletions Classes/Images.xcassets/AppIcon.appiconset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -29,6 +39,11 @@
"idiom" : "iphone",
"size" : "60x60",
"scale" : "3x"
},
{
"idiom" : "ios-marketing",
"size" : "1024x1024",
"scale" : "1x"
}
],
"info" : {
Expand Down
6 changes: 6 additions & 0 deletions Classes/Images.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
6 changes: 6 additions & 0 deletions Classes/Images.xcassets/Icons/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
12 changes: 12 additions & 0 deletions Classes/Images.xcassets/Icons/icon_delete.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"idiom" : "iphone",
"filename" : "tagDelete.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Binary file not shown.
23 changes: 22 additions & 1 deletion Classes/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "ViewController.h"
#import "SKTagView.h"
#import "CustomTagButton.h"
#import <Masonry/Masonry.h>
#import <HexColors/HexColors.h>

Expand All @@ -24,12 +25,31 @@ - (void)viewDidLoad {

self.colors = @[@"#7ecef4", @"#84ccc9", @"#88abda", @"#7dc1dd", @"#b6b8de"];
[self setupTagView];

CustomTagButton *button = [CustomTagButton buttonWithType:UIButtonTypeCustom];
button.backgroundColor = [UIColor redColor];
[button setImage:[UIImage imageNamed:@"icon_delete"] forState:UIControlStateNormal];
[button setTitle:@"Islam" forState:UIControlStateNormal];
[button setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
button.titleLabel.backgroundColor = [UIColor greenColor];
button.imageView.backgroundColor = [UIColor orangeColor];
[self.view addSubview:button];
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view).offset(100);
make.left.equalTo(self.view).offset(100);
}];

UIView *rulerView = [[UIView alloc] initWithFrame:CGRectMake(0, -5, 13.f, 40.f)];
rulerView.backgroundColor = [UIColor blackColor];
[button addSubview:rulerView];

}

#pragma mark - Private
- (void)setupTagView {
self.tagView = ({
SKTagView *view = [SKTagView new];
view.buttonClass = [CustomTagButton class];
view.backgroundColor = [UIColor whiteColor];
view.padding = UIEdgeInsetsMake(12, 12, 12, 12);
view.interitemSpacing = 15;
Expand All @@ -55,7 +75,8 @@ - (void)setupTagView {
tag.fontSize = 15;
//tag.font = [UIFont fontWithName:@"Courier" size:15];
//tag.enable = NO;
tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.image = [UIImage imageNamed:@"icon_delete"];
// tag.padding = UIEdgeInsetsMake(13.5, 12.5, 13.5, 12.5);
tag.bgColor = [UIColor hx_colorWithHexString: self.colors[idx % self.colors.count]];
tag.cornerRadius = 5;
[self.tagView addTag:tag];
Expand Down
Loading