@@ -99,11 +99,12 @@ public class SCLAlertView: UIViewController {
9999 let kCircleHeight : CGFloat = 56.0
100100 let kCircleIconHeight : CGFloat = 20.0
101101 let kTitleTop : CGFloat = 30.0
102- let kTitleHeight : CGFloat = 40 .0
102+ let kTitleHeight : CGFloat = 25 .0
103103 let kWindowWidth : CGFloat = 240.0
104104 var kWindowHeight : CGFloat = 178.0
105105 var kTextHeight : CGFloat = 90.0
106106 let kTextFieldHeight : CGFloat = 45.0
107+ let kTextViewdHeight : CGFloat = 80.0
107108 let kButtonHeight : CGFloat = 45.0
108109
109110 // Font
@@ -137,6 +138,7 @@ public class SCLAlertView: UIViewController {
137138 var durationTimer : NSTimer !
138139 var dismissBlock : DismissBlock ?
139140 private var inputs = [ UITextField] ( )
141+ private var input = [ UITextView] ( )
140142 internal var buttons = [ SCLButton] ( )
141143 private var selfReference : SCLAlertView ?
142144
@@ -181,10 +183,10 @@ public class SCLAlertView: UIViewController {
181183 viewText. textContainer. lineFragmentPadding = 0 ;
182184 viewText. font = UIFont ( name: kDefaultFont, size: 14 )
183185 // Colours
184- contentView. backgroundColor = 0xFFFFFF . toUIColor ( )
185- labelTitle. textColor = 0x4D4D4D . toUIColor ( )
186- viewText. textColor = 0x4D4D4D . toUIColor ( )
187- contentView. layer. borderColor = 0xCCCCCC . toCGColor ( )
186+ contentView. backgroundColor = UIColorFromRGB ( 0xFFFFFF )
187+ labelTitle. textColor = UIColorFromRGB ( 0x4D4D4D )
188+ viewText. textColor = UIColorFromRGB ( 0x4D4D4D )
189+ contentView. layer. borderColor = UIColorFromRGB ( 0xCCCCCC ) . CGColor
188190 //Gesture Recognizer for tapping outside the textinput
189191 let tapGesture = UITapGestureRecognizer ( target: self , action: #selector( SCLAlertView . tapped ( _: ) ) )
190192 tapGesture. numberOfTapsRequired = 1
@@ -210,6 +212,7 @@ public class SCLAlertView: UIViewController {
210212 consumedHeight += 14
211213 consumedHeight += kButtonHeight * CGFloat( buttons. count)
212214 consumedHeight += kTextFieldHeight * CGFloat( inputs. count)
215+ consumedHeight += kTextViewdHeight * CGFloat( input. count)
213216 let maxViewTextHeight = maxHeight - consumedHeight
214217 let viewTextWidth = kWindowWidth - 24
215218 let suggestedViewTextSize = viewText. sizeThatFits ( CGSizeMake ( viewTextWidth, CGFloat . max) )
@@ -247,6 +250,11 @@ public class SCLAlertView: UIViewController {
247250 txt. layer. cornerRadius = fieldCornerRadius
248251 y += kTextFieldHeight
249252 }
253+ for txt in input {
254+ txt. frame = CGRect ( x: 12 , y: y, width: kWindowWidth - 24 , height: 70 )
255+ //txt.layer.cornerRadius = fieldCornerRadius
256+ y += kTextViewdHeight
257+ }
250258 // Buttons
251259 for btn in buttons {
252260 btn. frame = CGRect ( x: 12 , y: y, width: kWindowWidth - 24 , height: 35 )
@@ -292,6 +300,22 @@ public class SCLAlertView: UIViewController {
292300 return txt
293301 }
294302
303+ public func addTextView( ) -> UITextView {
304+ // Update view height
305+ kWindowHeight += kTextViewdHeight
306+ // Add text view
307+ let txt = UITextView ( )
308+ // No placeholder with UITextView but you can use KMPlaceholderTextView library
309+ txt. font = UIFont ( name: kDefaultFont, size: 14 )
310+ //txt.autocapitalizationType = UITextAutocapitalizationType.Words
311+ //txt.clearButtonMode = UITextFieldViewMode.WhileEditing
312+ txt. layer. masksToBounds = true
313+ txt. layer. borderWidth = 1.0
314+ contentView. addSubview ( txt)
315+ input. append ( txt)
316+ return txt
317+ }
318+
295319 public func addButton( title: String , action: ( ) -> Void ) -> SCLButton {
296320 let btn = addButton ( title)
297321 btn. actionType = SCLActionType . Closure
@@ -359,7 +383,6 @@ public class SCLAlertView: UIViewController {
359383 var keyboardHasBeenShown : Bool = false
360384
361385 func keyboardWillShow( notification: NSNotification ) {
362- guard !keyboardHasBeenShown else { return }
363386 keyboardHasBeenShown = true
364387
365388 guard let userInfo = notification. userInfo else { return }
@@ -375,16 +398,16 @@ public class SCLAlertView: UIViewController {
375398 }
376399
377400 func keyboardWillHide( notification: NSNotification ) {
378- guard keyboardHasBeenShown else { return } //This could happen on the simulator (keyboard will be hidden)
379-
380- if ( self . tmpContentViewFrameOrigin != nil ) {
381- self . contentView. frame. origin. y = self . tmpContentViewFrameOrigin!. y
382- }
383- if ( self . tmpCircleViewFrameOrigin != nil ) {
384- self . circleBG. frame. origin. y = self . tmpCircleViewFrameOrigin!. y
401+ if ( keyboardHasBeenShown) { //This could happen on the simulator (keyboard will be hidden)
402+ if ( self . tmpContentViewFrameOrigin != nil ) {
403+ self . contentView. frame. origin. y = self . tmpContentViewFrameOrigin!. y
404+ }
405+ if ( self . tmpCircleViewFrameOrigin != nil ) {
406+ self . circleBG. frame. origin. y = self . tmpCircleViewFrameOrigin!. y
407+ }
408+
409+ keyboardHasBeenShown = false
385410 }
386-
387- keyboardHasBeenShown = false
388411 }
389412
390413 //Dismiss keyboard when tapped outside textfield & close SCLAlertView when hideWhenBackgroundViewIsTapped
@@ -449,7 +472,7 @@ public class SCLAlertView: UIViewController {
449472 viewColor = UIColor ( )
450473 var iconImage : UIImage ?
451474 let colorInt = colorStyle ?? style. defaultColorInt
452- viewColor = colorInt . toUIColor ( )
475+ viewColor = UIColorFromRGB ( colorInt )
453476 // Icon style
454477 switch style {
455478 case . Success:
@@ -534,9 +557,14 @@ public class SCLAlertView: UIViewController {
534557 for txt in inputs {
535558 txt. layer. borderColor = viewColor. CGColor
536559 }
560+
561+ for txt in input {
562+ txt. layer. borderColor = viewColor. CGColor
563+ }
564+
537565 for btn in buttons {
538566 btn. backgroundColor = viewColor
539- btn. setTitleColor ( colorTextButton ? . toUIColor ( ) ?? 0xFFFFFF . toUIColor ( ) , forState: UIControlState . Normal)
567+ btn. setTitleColor ( UIColorFromRGB ( colorTextButton ?? 0xFFFFFF ) , forState: UIControlState . Normal)
540568 }
541569
542570 // Adding duration
@@ -589,6 +617,16 @@ public class SCLAlertView: UIViewController {
589617 return defaultImage
590618 }
591619 }
620+
621+ // Helper function to convert from RGB to UIColor
622+ func UIColorFromRGB( rgbValue: UInt ) -> UIColor {
623+ return UIColor (
624+ red: CGFloat ( ( rgbValue & 0xFF0000 ) >> 16 ) / 255.0 ,
625+ green: CGFloat ( ( rgbValue & 0x00FF00 ) >> 8 ) / 255.0 ,
626+ blue: CGFloat ( rgbValue & 0x0000FF ) / 255.0 ,
627+ alpha: CGFloat ( 1.0 )
628+ )
629+ }
592630}
593631
594632// ------------------------------------
0 commit comments