Skip to content

Commit 120a76d

Browse files
committed
Merge branch 'release/1.1'
2 parents 95af3bb + 77e55b0 commit 120a76d

File tree

6 files changed

+141
-35
lines changed

6 files changed

+141
-35
lines changed

Example/FreakingSimpleRoundImageView/Base.lproj/Main.storyboard

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<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">
3-
<device id="retina4_7" orientation="landscape">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="vXZ-lx-hvc">
3+
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
66
<dependencies>
7-
<deployment identifier="iOS"/>
8-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
7+
<deployment version="2304" identifier="iOS"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14088"/>
99
<capability name="Aspect ratio constraints" minToolsVersion="5.1"/>
10+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
1011
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
1112
</dependencies>
1213
<scenes>
1314
<!--View Controller-->
1415
<scene sceneID="ufC-wZ-h7g">
1516
<objects>
1617
<viewController id="vXZ-lx-hvc" customClass="ViewController" customModule="FreakingSimpleRoundImageView_Example" customModuleProvider="target" sceneMemberID="viewController">
17-
<layoutGuides>
18-
<viewControllerLayoutGuide type="top" id="jyV-Pf-zRb"/>
19-
<viewControllerLayoutGuide type="bottom" id="2fi-mo-0CV"/>
20-
</layoutGuides>
2118
<view key="view" contentMode="scaleToFill" id="kh9-bI-dsS">
22-
<rect key="frame" x="0.0" y="0.0" width="667" height="375"/>
19+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
2320
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
2421
<subviews>
2522
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="center" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="Boba.jpeg" translatesAutoresizingMaskIntoConstraints="NO" id="qLA-T1-VnE" customClass="RoundImageView" customModule="FreakingSimpleRoundImageView">
26-
<rect key="frame" x="32" y="37.5" width="300" height="300"/>
23+
<rect key="frame" x="37.5" y="52" width="300" height="300"/>
2724
<constraints>
2825
<constraint firstAttribute="width" secondItem="qLA-T1-VnE" secondAttribute="height" multiplier="1:1" id="Di2-Wc-Rf2"/>
2926
<constraint firstAttribute="width" constant="300" id="y4k-Vy-41d"/>
@@ -37,11 +34,13 @@
3734
</userDefinedRuntimeAttribute>
3835
</userDefinedRuntimeAttributes>
3936
</imageView>
40-
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Image credit: starwars.com" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="2" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EEe-ef-qZ7">
41-
<rect key="frame" x="340" y="157.5" width="317" height="60"/>
37+
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="EEe-ef-qZ7">
38+
<rect key="frame" x="84" y="393" width="207" height="41"/>
4239
<constraints>
4340
<constraint firstAttribute="height" relation="greaterThanOrEqual" constant="60" id="Bak-0k-kjj"/>
4441
</constraints>
42+
<string key="text">Image credit: starwars.com
43+
Tap image for more!</string>
4544
<fontDescription key="fontDescription" type="system" pointSize="17"/>
4645
<nil key="textColor"/>
4746
<nil key="highlightedColor"/>
@@ -60,17 +59,18 @@
6059
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
6160
<constraints>
6261
<constraint firstItem="EEe-ef-qZ7" firstAttribute="top" secondItem="qLA-T1-VnE" secondAttribute="bottom" constant="41" id="3NI-Z2-dO5"/>
63-
<constraint firstItem="qLA-T1-VnE" firstAttribute="centerX" secondItem="kh9-bI-dsS" secondAttribute="centerX" id="46y-lC-LEi"/>
62+
<constraint firstItem="qLA-T1-VnE" firstAttribute="centerX" secondItem="GvL-2a-UeU" secondAttribute="centerX" id="46y-lC-LEi"/>
6463
<constraint firstItem="qLA-T1-VnE" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="5CM-jn-ozu"/>
65-
<constraint firstItem="qLA-T1-VnE" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="64" id="BzW-Wy-f41"/>
66-
<constraint firstItem="qLA-T1-VnE" firstAttribute="top" secondItem="jyV-Pf-zRb" secondAttribute="bottom" constant="32" id="Cgb-Ri-oi8"/>
64+
<constraint firstItem="qLA-T1-VnE" firstAttribute="leading" secondItem="GvL-2a-UeU" secondAttribute="leading" constant="64" id="BzW-Wy-f41"/>
65+
<constraint firstItem="qLA-T1-VnE" firstAttribute="top" secondItem="GvL-2a-UeU" secondAttribute="top" constant="32" id="Cgb-Ri-oi8"/>
6766
<constraint firstItem="EEe-ef-qZ7" firstAttribute="centerY" secondItem="qLA-T1-VnE" secondAttribute="centerY" id="Di3-ek-u2w"/>
6867
<constraint firstItem="qLA-T1-VnE" firstAttribute="centerY" secondItem="kh9-bI-dsS" secondAttribute="centerY" id="Ihe-om-3bF"/>
6968
<constraint firstItem="EEe-ef-qZ7" firstAttribute="leading" secondItem="qLA-T1-VnE" secondAttribute="trailing" constant="8" id="P2U-8W-G1w"/>
70-
<constraint firstAttribute="trailing" secondItem="EEe-ef-qZ7" secondAttribute="trailing" constant="10" id="cBa-de-J3c"/>
69+
<constraint firstItem="GvL-2a-UeU" firstAttribute="trailing" secondItem="EEe-ef-qZ7" secondAttribute="trailing" constant="10" id="cBa-de-J3c"/>
7170
<constraint firstItem="EEe-ef-qZ7" firstAttribute="centerX" secondItem="qLA-T1-VnE" secondAttribute="centerX" id="go4-Ia-JEz"/>
72-
<constraint firstItem="qLA-T1-VnE" firstAttribute="leading" secondItem="kh9-bI-dsS" secondAttribute="leading" constant="32" id="utP-vH-wv1"/>
71+
<constraint firstItem="qLA-T1-VnE" firstAttribute="leading" secondItem="GvL-2a-UeU" secondAttribute="leading" constant="32" id="utP-vH-wv1"/>
7372
</constraints>
73+
<viewLayoutGuide key="safeArea" id="GvL-2a-UeU"/>
7474
<variation key="default">
7575
<mask key="constraints">
7676
<exclude reference="5CM-jn-ozu"/>
@@ -108,6 +108,9 @@
108108
</mask>
109109
</variation>
110110
</view>
111+
<connections>
112+
<outlet property="imageView" destination="qLA-T1-VnE" id="hTY-oV-ANF"/>
113+
</connections>
111114
</viewController>
112115
<placeholder placeholderIdentifier="IBFirstResponder" id="x5A-6p-PRh" sceneMemberID="firstResponder"/>
113116
</objects>

Example/FreakingSimpleRoundImageView/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0.2</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>
22-
<string>3</string>
22+
<string>4</string>
2323
<key>LSRequiresIPhoneOS</key>
2424
<true/>
2525
<key>UILaunchStoryboardName</key>

Example/FreakingSimpleRoundImageView/ViewController.swift

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,77 @@
77
//
88

99
import UIKit
10+
import FreakingSimpleRoundImageView
11+
12+
private let defaultAnimationDuration: TimeInterval = 0.2
1013

1114
class ViewController: UIViewController {
15+
1216
/*
13-
A long long time ago...
14-
I ate a freakin' delicious pie.
15-
With lime, mint, cashew, Swift and Interface Builder support.
16-
Ah, good ol' days!
17+
A long long time ago...
18+
I ate a freakin' delicious pie.
19+
With lime, mint, cashew, Swift and Interface Builder support.
20+
Ah, good ol' days!
1721
*/
22+
23+
24+
// MARK: - IBOutlets
25+
26+
@IBOutlet weak var imageView: RoundImageView!
27+
28+
29+
// MARK: - Lifecycle
30+
31+
override func viewDidLoad() {
32+
super.viewDidLoad()
33+
let recognizer = UITapGestureRecognizer(target: self, action: #selector(presentRoundingModeSwitcher))
34+
imageView.isUserInteractionEnabled = true
35+
imageView.addGestureRecognizer(recognizer)
36+
}
37+
38+
39+
// MARK: - Other
40+
41+
@objc func presentRoundingModeSwitcher() {
42+
let alert = UIAlertController(title: "Rounding mode", message: nil, preferredStyle: .actionSheet)
43+
44+
// MARK: Rectangle
45+
alert.addAction(UIAlertAction(title: "Rectangle", style: .default) { [weak self] _ in
46+
UIView.animate(withDuration: defaultAnimationDuration) {
47+
self?.imageView.roundingMode = .rectangle
48+
}
49+
})
50+
51+
// MARK: Round
52+
alert.addAction(UIAlertAction(title: "Circle", style: .default) { [weak self] _ in
53+
UIView.animate(withDuration: defaultAnimationDuration) {
54+
self?.imageView.roundingMode = .round
55+
}
56+
})
57+
58+
// MARK: Rounded corners
59+
alert.addAction(UIAlertAction(title: "Rounded corners", style: .default) { [weak self] _ in
60+
let radiusAlert = UIAlertController(title: "Corner radius", message: nil, preferredStyle: .alert)
61+
radiusAlert.addTextField(configurationHandler: { textField in
62+
textField.placeholder = "radius"
63+
textField.keyboardType = .numberPad
64+
})
65+
66+
radiusAlert.addAction(UIAlertAction(title: "Ok", style: .default) { action in
67+
guard let raw = radiusAlert.textFields?.first?.text, let radius = Double(raw) else {
68+
return
69+
}
70+
71+
UIView.animate(withDuration: defaultAnimationDuration) {
72+
self?.imageView?.roundingMode = .roundedCorners(radius: CGFloat(radius))
73+
}
74+
})
75+
76+
radiusAlert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
77+
self?.present(radiusAlert, animated: true, completion: nil)
78+
})
79+
80+
alert.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
81+
present(alert, animated: true, completion: nil)
82+
}
1883
}

FreakingSimpleRoundImageView.podspec

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,9 @@
88

99
Pod::Spec.new do |s|
1010
s.name = 'FreakingSimpleRoundImageView'
11-
s.version = '1.0.2'
11+
s.version = '1.1'
1212
s.summary = 'A freakin simple RoundImageView. With Interface Builder support.'
1313

14-
# This description is used to generate tags and improve search results.
15-
# * Think: What does it do? Why did you write it? What is the focus?
16-
# * Try to keep it short, snappy and to the point.
17-
# * Write the description between the DESC delimiters below.
18-
# * Finally, don't worry about the indent, CocoaPods strips it!
19-
2014
s.description = 'Very simple RoundImageView, with Interface Builder support. In swift. Grab it and make something neat.'
2115
s.homepage = 'https://github.com/realbonus/FreakingSimpleRoundImageView'
2216
s.screenshots = 'https://raw.githubusercontent.com/RealBonus/FreakingSimpleRoundImageView/master/Screenshots/IB.png', 'https://raw.githubusercontent.com/RealBonus/FreakingSimpleRoundImageView/master/Screenshots/Attributes.png'

FreakingSimpleRoundImageView/Classes/RoundImageView.swift

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import UIKit
1111
@IBDesignable
1212
open class RoundImageView: UIImageView {
1313

14+
// MARK: Border properties
15+
1416
@IBInspectable
1517
open var borderWidth: CGFloat {
1618
set {
@@ -39,23 +41,45 @@ open class RoundImageView: UIImageView {
3941
}
4042
}
4143

44+
45+
// MARK: Rounding mode
46+
47+
open var roundingMode: RoundingMode = .round {
48+
didSet {
49+
updateLayer()
50+
setNeedsDisplay()
51+
}
52+
}
53+
54+
55+
// MARK: Internal
56+
4257
override open var frame: CGRect {
4358
didSet {
44-
if frame.width < frame.height {
45-
layer.cornerRadius = frame.width / 2
46-
} else {
47-
layer.cornerRadius = frame.height / 2
48-
}
59+
updateLayer()
4960
}
5061
}
5162

5263
override open var bounds: CGRect {
5364
didSet {
65+
updateLayer()
66+
}
67+
}
68+
69+
private func updateLayer() {
70+
switch roundingMode {
71+
case .rectangle:
72+
layer.cornerRadius = 0
73+
74+
case .round:
5475
if bounds.width < bounds.height {
5576
layer.cornerRadius = bounds.width / 2
5677
} else {
5778
layer.cornerRadius = bounds.height / 2
5879
}
80+
81+
case .roundedCorners(let radius):
82+
layer.cornerRadius = radius
5983
}
6084
}
6185
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// RoundingMode.swift
3+
// FreakingSimpleRoundImageView
4+
//
5+
// Created by Anokhov Pavel on 07/04/2018.
6+
//
7+
8+
import Foundation
9+
10+
11+
/// Frame rounding mode
12+
///
13+
/// - rectangle: Regular square imare
14+
/// - round: Round frame
15+
/// - roundedCorners: Frame with custom corner radius
16+
public enum RoundingMode {
17+
case rectangle
18+
case round
19+
case roundedCorners(radius: CGFloat)
20+
}

0 commit comments

Comments
 (0)