OnClick Label Calling with PhoneNumber
On click Label Call dynamically
<***********Steps to create calling Button**********>
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
<string>tel</string>
</array>
</dict>
- Add label in ViewController dynamically by using CGPoints.
//declare label
let phoneNumberLabel:UILabel = UILabel(frame: CGRectMake(85, 220, 120, 45))
//In viewDidLoad()
override func viewDidLoad() {
super.viewDidLoad()
phoneNumberLabel.bounds = CGRectMake(CGRectGetMidX(self.view.frame), 220, 120, 45)
phoneNumberLabel.text = "Click To Call"
self.view.addSubview(phoneNumberLabel)
}
Create An touchesBegan Event in View Controller
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInView(self.view)
if CGRectContainsPoint(phoneNumberLabel.frame, location) {
UIApplication.sharedApplication().openURL(NSURL(string: "tel://1234567890")!)
}
}
}
<*******OR********>
<***********Steps to create calling label with Outlet**********>
Add pies of code in info.plist .
</dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>telprompt</string>
<string>tel</string>
</array>
</dict>
- Add Label in Storyboard.
Create An Label Outlet in View Controller.
@IBOutlet var callPhoneNumberLabel: UILabel!
Create Function for Calling label.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInView(self.view)
if CGRectContainsPoint(callPhoneNumberLabel.frame, location) {
UIApplication.sharedApplication().openURL(NSURL(string: "tel://1234567890")!)
}
}
}
Finished Run and Check ......happy Coding
No comments:
Post a Comment