Skip to content

Commit

Permalink
This patch allows a user to specify additional options such as
Browse files Browse the repository at this point in the history
 show/hide the circular view.
 corner radius for content, field and buttons (use 0.0 to get a flat look)
  • Loading branch information
appsailor committed Oct 18, 2015
1 parent 28b40ff commit 0028d47
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions SCLAlertView/SCLAlertView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public class SCLAlertView: UIViewController {

// UI Options
public var showCloseButton = true
public var showCircularIcon = true
public var contentViewCornerRadius : CGFloat = 5.0
public var fieldCornerRadius : CGFloat = 3.0
public var buttonCornerRadius : CGFloat = 3.0

// Members declaration
var baseView = UIView()
Expand Down Expand Up @@ -126,7 +130,7 @@ public class SCLAlertView: UIViewController {
baseView.addSubview(contentView)
// Content View
contentView.backgroundColor = UIColor(white:1, alpha:1)
contentView.layer.cornerRadius = 5
contentView.layer.cornerRadius = contentViewCornerRadius
contentView.layer.masksToBounds = true
contentView.layer.borderWidth = 0.5
contentView.addSubview(labelTitle)
Expand Down Expand Up @@ -197,24 +201,30 @@ public class SCLAlertView: UIViewController {
var x = (sz.width - kWindowWidth) / 2
var y = (sz.height - windowHeight - (kCircleHeight / 8)) / 2
contentView.frame = CGRect(x:x, y:y, width:kWindowWidth, height:windowHeight)
contentView.layer.cornerRadius = contentViewCornerRadius
y -= kCircleHeightBackground * 0.6
x = (sz.width - kCircleHeightBackground) / 2
circleBG.frame = CGRect(x:x, y:y+6, width:kCircleHeightBackground, height:kCircleHeightBackground)

//adjust Title frame based on circularIcon show/hide flag
let titleOffset : CGFloat = showCircularIcon ? 0.0 : -12.0
labelTitle.frame = labelTitle.frame.offsetBy(dx: 0, dy: titleOffset)

// Subtitle
y = kTitleTop + kTitleHeight
y = kTitleTop + kTitleHeight + titleOffset
viewText.frame = CGRect(x:12, y:y, width: kWindowWidth - 24, height:kTextHeight)
viewText.frame = CGRect(x:12, y:y, width: viewTextWidth, height:viewTextHeight)
// Text fields
y += viewTextHeight + 14.0
for txt in inputs {
txt.frame = CGRect(x:12, y:y, width:kWindowWidth - 24, height:30)
txt.layer.cornerRadius = 3
txt.layer.cornerRadius = fieldCornerRadius
y += kTextFieldHeight
}
// Buttons
for btn in buttons {
btn.frame = CGRect(x:12, y:y, width:kWindowWidth - 24, height:35)
btn.layer.cornerRadius = 3
btn.layer.cornerRadius = buttonCornerRadius
y += kButtonHeight
}
}
Expand Down Expand Up @@ -463,6 +473,10 @@ public class SCLAlertView: UIViewController {
addButton(txt, target:self, selector:Selector("hideView"))
}

//hidden/show circular view based on the ui option
circleView.hidden = !showCircularIcon
circleBG.hidden = !showCircularIcon

// Alert view colour and images
circleView.backgroundColor = viewColor
// Spinner / icon
Expand Down

0 comments on commit 0028d47

Please sign in to comment.