Skip to content

Commit

Permalink
Merge pull request #196 from FelipeNBrito/master
Browse files Browse the repository at this point in the history
Custom alert created. Customizable: Color and Icon
  • Loading branch information
vikmeup committed Jun 8, 2016
2 parents c087c84 + 3ce1291 commit 93e90c1
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Example/SCLAlertViewExample/Main.storyboard
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10116" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="ngj-nl-OHz">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="10117" systemVersion="15E65" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" initialViewController="ngj-nl-OHz">
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="10085"/>
Expand Down Expand Up @@ -80,6 +80,13 @@
<action selector="showEdit:" destination="ngj-nl-OHz" eventType="touchUpInside" id="Cce-Yv-6Q3"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="ioy-Wh-g2g">
<rect key="frame" x="234" y="437" width="132" height="30"/>
<state key="normal" title="Show Custom Alert"/>
<connections>
<action selector="showCustomAlert:" destination="ngj-nl-OHz" eventType="touchUpInside" id="mOn-fE-qni"/>
</connections>
</button>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<constraints>
Expand All @@ -93,13 +100,15 @@
<constraint firstAttribute="centerX" secondItem="Uhe-aS-BHL" secondAttribute="centerX" constant="0.5" id="JiZ-Sr-LRZ"/>
<constraint firstItem="McK-98-W7e" firstAttribute="centerY" secondItem="arb-3g-Toj" secondAttribute="centerY" constant="258" id="Olk-US-7Qt"/>
<constraint firstItem="VWR-vv-K1w" firstAttribute="centerX" secondItem="dOp-SD-9bQ" secondAttribute="centerX" id="R9D-mp-DSX"/>
<constraint firstItem="ioy-Wh-g2g" firstAttribute="centerX" secondItem="7du-np-8iv" secondAttribute="centerX" id="TJm-hW-AWH"/>
<constraint firstItem="arb-3g-Toj" firstAttribute="centerX" secondItem="G4y-kv-ZRs" secondAttribute="centerX" id="am6-Lr-rTd"/>
<constraint firstItem="VWR-vv-K1w" firstAttribute="centerX" secondItem="ism-f4-jWc" secondAttribute="centerX" id="fku-3F-Xme"/>
<constraint firstItem="9bA-oa-lCU" firstAttribute="top" secondItem="McK-98-W7e" secondAttribute="bottom" constant="8" id="fph-BA-FU4"/>
<constraint firstItem="dOp-SD-9bQ" firstAttribute="centerX" secondItem="arb-3g-Toj" secondAttribute="centerX" id="gPO-a1-Hre"/>
<constraint firstItem="McK-98-W7e" firstAttribute="leading" secondItem="ism-f4-jWc" secondAttribute="leading" id="kzA-aj-lPP"/>
<constraint firstItem="ism-f4-jWc" firstAttribute="top" secondItem="VWR-vv-K1w" secondAttribute="bottom" constant="20" id="m91-r8-IcB"/>
<constraint firstItem="dOp-SD-9bQ" firstAttribute="top" secondItem="Uhe-aS-BHL" secondAttribute="bottom" constant="20" id="rWX-S4-YjF"/>
<constraint firstItem="ioy-Wh-g2g" firstAttribute="top" secondItem="9bA-oa-lCU" secondAttribute="bottom" constant="16" id="wfc-Ch-5d6"/>
</constraints>
<variation key="default">
<mask key="constraints">
Expand Down
14 changes: 14 additions & 0 deletions Example/SCLAlertViewExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ class ViewController: UIViewController {

alert.showInfo("Login", subTitle: "", duration: 10)
}

@IBAction func showCustomAlert(sender: AnyObject) {

let alert = SCLAlertView()
alert.addButton("First Button", target:self, selector:#selector(ViewController.firstButton))
alert.addButton("Second Button") {
print("Second button tapped")
}

let icon = UIImage(named:"custom_icon.png")
let color = UIColor.orangeColor()

alert.showCustom("Custom Color", subTitle: "Custom color", color: color, icon: icon!)
}

func firstButton() {
print("First button tapped")
Expand Down
Binary file added Example/SCLAlertViewExample/custom_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,22 @@ public class SCLAlertView: UIViewController {
}
}

// showCustom(view, title, subTitle, UIColor, UIImage)
public func showCustom(title: String, subTitle: String, color: UIColor, icon: UIImage, closeButtonTitle:String?=nil, duration:NSTimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.Success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .TopToBottom) -> SCLAlertViewResponder {


var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0

color.getRed(&red, green: &green, blue: &blue, alpha: &alpha)

var colorAsUInt32 : UInt32 = 0
colorAsUInt32 += UInt32(red * 255.0) << 16 + UInt32(green * 255.0) << 8 + UInt32(blue * 255.0)

let colorAsUInt = UInt(colorAsUInt32)

return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .Success, colorStyle: colorAsUInt, colorTextButton: colorTextButton, circleIconImage: icon, animationStyle: animationStyle)
}

// showSuccess(view, title, subTitle)
public func showSuccess(title: String, subTitle: String, closeButtonTitle:String?=nil, duration:NSTimeInterval=0.0, colorStyle: UInt=SCLAlertViewStyle.Success.defaultColorInt, colorTextButton: UInt=0xFFFFFF, circleIconImage: UIImage? = nil, animationStyle: SCLAnimationStyle = .TopToBottom) -> SCLAlertViewResponder {
return showTitle(title, subTitle: subTitle, duration: duration, completeText:closeButtonTitle, style: .Success, colorStyle: colorStyle, colorTextButton: colorTextButton, circleIconImage: circleIconImage, animationStyle: animationStyle)
Expand Down

0 comments on commit 93e90c1

Please sign in to comment.