Add Navigation Bar in UICollectionView in swift 4, iOS 11 - uicollectionview

After upgrading the iOS 11 and swift 4(Xcode 9), I got lots of UI problem. :(
The most unsolvable problem is Navigation Problem. I put the Navigation Bar in UICollectionView Controller. Navigation bar height does not show properly and however I write the code.
I set navigation bar height "100". I write this code in ViewDidLoad().
if #available(iOS 11.0, *) {
print("IOS 11 Screen")
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
]
navigationItem.largeTitleDisplayMode = .never
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
} else {
print("lower than IOS 11 Screen")
// Fallback on earlier versions
}
collectionview?.frame = CGRect(x: 0, y: 10, width: UIScreen.main.bounds.width, height: (UIScreen.main.bounds.height + 20)) <br>
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
override func viewWillAppear(_ animated: Bool) {
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}
However, I tried with this code. Nothing works for me.
I also tried to open the storyboard with source code view and I edit the height of Navigation bar. But, it also does not work.
Can anyone help me please? I have been trying to solve this problem since last two days.

Please check :
override func viewDidLoad() {
if #available(iOS 11.0, *) {
print("IOS 11 Screen")
UINavigationBar.appearance().largeTitleTextAttributes = [
NSForegroundColorAttributeName: UIColor.white,
]
self.navigationController?.navigationBar.prefersLargeTitles = true // added this line
navigationItem.largeTitleDisplayMode = .never
} else {
print("lower than IOS 11 Screen")
// Fallback on earlier versions
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let height: CGFloat = 100 //whatever height you want
let bounds = self.navigationController!.navigationBar.bounds
self.navigationController?.navigationBar.frame = CGRect(x: 0, y: 0, width: bounds.width, height: bounds.height + height)
}

Related

SwiftUI: Is it possible to create macOS HUDs like the ones that comes up when changing brightness/volume or building xode projects?

I started playing with SwiftUI recently and i can't figure out how to create the kind of HUDs that come up when you build an Xcode project or when you change the screen brightness. Does anybody know how to recreate these? Here is an image for reference:
I was trying to implement this yesterday and finally kind of found a solution, maybe not perfect, but it works.
The basic idea is that you need to create a new borderless window and then close it after it is been displayed. This is the code I use, hope it helps you.
Button("Show HUD") {
// create a borderless panel
let window = NSPanel(contentRect: NSRect(x: 0, y: 0, width: 500, height: 500), styleMask: [.fullSizeContentView, .borderless, .hudWindow], backing: .buffered, defer: false)
window.center()
// make transparent background
window.backgroundColor = .clear
let rect = NSScreen.main!.frame
// move the window to bottom center
let frame = NSRect(origin: window.frame.offsetBy(dx: 125, dy: -rect.height / 4).origin, size: window.frame.size)
window.setFrame(frame, display: true)
// create hosting view
window.contentView = NSHostingView(rootView: HUDView())
// show the window
window.makeKeyAndOrderFront(nil)
// Auto close the window after 1.8s
DispatchQueue.main.asyncAfter(deadline: .now() + 1.8) {
window.close()
}
}
And then define your HUDView
struct HUDView: View {
#State var showHUD: Bool = false
var body: some View {
ZStack {
VStack {}
.background(.clear)
.frame(width: 200, height: 200)
.onAppear {
withAnimation(.easeInOut(duration: 0.3)) {
showHUD = true
}
}
if showHUD {
VStack(spacing: 20) {
Image(systemName: "doc.on.clipboard.fill").font(.system(size: 72))
Text("Code Copied").font(.system(size: 20))
}
.frame(width: 200, height: 200)
// the background could be .regularMaterial, but for some reason it can not works, so instead I created my own BlurView...
.background(BlurView())
.cornerRadius(20)
.foregroundColor(.white.opacity(0.8))
.overlay(RoundedRectangle(cornerRadius: 20).strokeBorder(.white.opacity(0.15), lineWidth: 1))
}
}
}
}
BlurView defines
struct BlurView: NSViewRepresentable {
func makeNSView(context: Context) -> NSVisualEffectView {
let blurView = NSVisualEffectView()
blurView.blendingMode = .behindWindow
blurView.isEmphasized = true
blurView.material = .hudWindow
blurView.autoresizingMask = [.width, .height]
blurView.state = NSVisualEffectView.State.active
return blurView
}
func updateNSView(_ nsView: NSVisualEffectView, context: Context) {
}
}
The preview should show something like below, pretty cool 😎 , isn't it?

How to scroll collectionViewCell smoothly like news ticker at bottom in swift 4 ios

I want to scroll collectionView cells slowly ,Smoothly and automatically like marquee in swift 4.
try to animate with this and works perfectly
func startScrolling(){
let co = collectionView.contentOffset.x
let no = co + 1
UIView.animate(withDuration: 0.001, delay: 0, options: .curveEaseInOut, animations: { [weak self]() -> Void in
self?.collectionView.contentOffset = CGPoint(x: no, y: 0)
}) { [weak self](finished) -> Void in
self?.startScrolling()
}
}
But from this not get Index and not clickable also , Need help

programmatically create VC, Use integers from UItext field in formula and perform a calculation when UIButton is tapped

all, this code does not throw errors now but the screen is blank. I am trying to create a simple calculator. user will input numbers into 3 separate UIText fields, push a button and a UILabel would give answer. I know i do not have labels yet. i first built a container to hold text fields but then my "CalculateTapped" could not see the textFields as variables.
Question. 1 why is my screen now black?
Question. 2. why could i not get CalculateTapped to read UIText fields from my lazy var "" view earlier?
If anyone has any input i would greatly appreciate it. trying to get away from storyboards.
import UIKit
class PitchLineVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let view = UIView()
()
view.backgroundColor = .white
view.anchor(top: view.topAnchor, left: view.leftAnchor,bottom: view.bottomAnchor, right: view.rightAnchor);
configureNavigationBar()
// looks for keyboard instance
NotificationCenter.default.addObserver(self, selector: #selector(PitchLineVC.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(PitchLineVC.keyboarWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
// keeps screen from rotating
override var shouldAutorotate: Bool {
return false
}
// Add text fields for user input to calculate pitch
private lazy var areaTxt: UITextField! = {
let area = UITextField()
area.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: -100).isActive = true
area.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -300).isActive = true
area.placeholder = "Bar Area"
area.textAlignment = .center
area.borderStyle = UITextField.BorderStyle.line
area.backgroundColor = UIColor.white
area.textColor = UIColor.black
area.keyboardType = UIKeyboardType.decimalPad
// view.addSubview(area)
return(area)
}()
private lazy var areaTop: UITextField! = {
let area = UITextField()
area.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true
area.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -200).isActive = true
area.placeholder = "Top Area of Bar"
area.textAlignment = .center
area.borderStyle = UITextField.BorderStyle.line
area.backgroundColor = UIColor.white
area.textColor = UIColor.black
area.keyboardType = UIKeyboardType.decimalPad
// view.addSubview(area)
return(area)
}()
private lazy var lineLength: UITextField! = {
let line = UITextField()
line.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: -100).isActive = true
line.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -300).isActive = true
// line.anchor(top: view.bottomAnchor, paddingTop: -80,width: 100, height: 35)
line.placeholder = "Line Length"
line.textAlignment = .center
line.borderStyle = UITextField.BorderStyle.line
line.backgroundColor = UIColor.white
line.textColor = UIColor.black
line.keyboardType = UIKeyboardType.decimalPad
// view.addSubview(line)
return (line)
}()
#objc func CalculateTapped(){
print("Button Tapped")
let AreaTotal = Double(areaTxt.text!)
let AreaTop = Double(areaTop.text!)
let Line = Double(lineLength.text!)
if AreaTotal != nil && AreaTop != nil && Line != nil{
let LineMove = -(((AreaTotal! / 2) - AreaTop!) / Line!)
movepitchline.text = NSString(format: "%.3f", LineMove) as String
}
}
func addCalculateButton(){
let Calculate = UIButton()
Calculate.addTarget(self, action: #selector(CalculateTapped), for: .touchUpInside)
Calculate.centerXAnchor.constraint(equalTo: view.centerXAnchor, constant: -100).isActive = true
Calculate.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: -400).isActive = true
Calculate.anchor(top: view.bottomAnchor, paddingTop: -80,
width: 100, height: 35)
view.addSubview(Calculate)
}
let movepitchline: UILabel = {
let label = UILabel()
label.textAlignment = .right
label.frame = CGRect(x: 10, y: 380, width: 220, height: 35)
label.text = "Move Pitch:"
label.font = UIFont.boldSystemFont(ofSize: 23)
label.textColor = .black
return label
}()
// When keyboard displays the UIView shift up
#objc func keyboardWillShow(notification: NSNotification) {
guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
// if keyboard size is not available for some reason, dont do anything
return
}
// move the root view up by the distance of keyboard height
self.view.frame.origin.y = 150 - keyboardSize.height
}
#objc func keyboarWillHide(notification: NSNotification){
self.view.frame.origin.y = 0//\\100 + keyboardSize.height
}
// select outside text box to dismiss selection
#objc func handleDismiss(notification: NSNotification) {
dismiss(animated: true, completion: nil)
}
func configureNavigationBar() {
navigationController?.navigationBar.barTintColor = .appBlue
navigationController?.navigationBar.barStyle = .black
navigationItem.title = "Pass Pitch and Diameters"
navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "Home_2x").withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleDismiss))
}
}
import UIKit
class PitchLineVC: UIViewController {
lazy var pitchlogoView: UIImageView = {
let iv = UIImageView()
iv.contentMode = .scaleAspectFit
iv.clipsToBounds = true
iv.image = #imageLiteral(resourceName: "PITCH LINE")
return iv
}()
lazy var areaTxt: UITextField! = {
let tf = UITextField()
tf.placeholder = "Bar Area"
tf.textAlignment = .center
tf.borderStyle = UITextField.BorderStyle.line
tf.backgroundColor = UIColor.white
tf.textColor = UIColor.black
tf.keyboardType = UIKeyboardType.decimalPad
return(tf)
}()
lazy var areaTop: UITextField! = {
let tf = UITextField()
tf.placeholder = "Top Area of Bar"
tf.textAlignment = .center
tf.borderStyle = UITextField.BorderStyle.line
tf.backgroundColor = UIColor.white
tf.textColor = UIColor.black
tf.keyboardType = UIKeyboardType.decimalPad
return(tf)
}()
lazy var lineLength: UITextField! = {
let tf = UITextField()
tf.placeholder = "Line Length"
tf.textAlignment = .center
tf.borderStyle = UITextField.BorderStyle.line
tf.backgroundColor = UIColor.white
tf.textColor = UIColor.black
tf.keyboardType = UIKeyboardType.decimalPad
return (tf)
}()
lazy var movepitchline1: UILabel = {
let lb = UILabel()
lb.textAlignment = .right
lb.frame = CGRect(x: 10, y: 380, width: 220, height: 35)
lb.text = "Move Pitch: + is up, - is down"
lb.textAlignment = .center
lb.font = UIFont.boldSystemFont(ofSize: 23)
lb.textColor = .black
return (lb)
}()
lazy var movepitchline: UILabel = {
let lb = UILabel()
lb.textAlignment = .right
lb.frame = CGRect(x: 10, y: 380, width: 220, height: 35)
lb.text = ""
lb.textAlignment = .center
lb.font = UIFont.boldSystemFont(ofSize: 23)
lb.textColor = .black
return (lb)
}()
let calculateButton: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = UIColor.init(red: 48/255, green: 173/255, blue: 99/255, alpha: 1)
button.layer.cornerRadius = 25.0
button.tintColor = UIColor.white
button.layer.shadowColor = UIColor.darkGray.cgColor
button.layer.shadowRadius = 6
button.layer.shadowOpacity = 0.7
button.layer.shadowOffset = CGSize(width: 0, height: 0)
button.setTitle("Calculate", for: .normal)
button.titleLabel?.font = UIFont(name: "Copperplate", size: 22)
button.addTarget(self, action: #selector(handleCalculate), for: .touchUpInside)
return button
}()
#objc func handleDismiss(notification: NSNotification) {
dismiss(animated: true, completion: nil)
}
//sets trigger for keyboard dismiss
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
super.touchesBegan(touches, with: event)
}
// Mark: Init
override func viewDidLoad() {
super.viewDidLoad()
configureNavigationBar()
configureViewComponent()
// looks for keyboard instance
NotificationCenter.default.addObserver(self, selector: #selector(PitchLineVC.keyboardWillShow), name: UIResponder.keyboardWillShowNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(PitchLineVC.keyboarWillHide), name: UIResponder.keyboardWillHideNotification, object: nil)
}
// keeps screen from rotating
override var shouldAutorotate: Bool {
return false
}
// Mark: Selectors
#objc func handleCalculate()
{
print("calculate")
guard let AreaTotal = Double(areaTxt.text!) else {return}
guard let AreaTop = Double(areaTop.text!) else {return}
guard let Line = Double(lineLength.text!) else {return}
if AreaTotal != 0 && AreaTop != 0 && Line != 0{
let LineMove = -(((AreaTotal / 2) - AreaTop) / Line)
print(LineMove)
movepitchline.text = NSString(format: "%.3f", LineMove) as String
} else{
print("Error in fields, please check entry")
}
}
func configureViewComponent(){
view.backgroundColor = .white
view.addSubview(pitchlogoView)
pitchlogoView.anchor(top: view.topAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 120, paddingLeft: 0, paddingBottom: 0, paddingRight: 0, width: 250, height: 110)
view.addSubview(areaTxt)
areaTxt.anchor(top: pitchlogoView.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 15, paddingLeft: 80, paddingBottom: 0, paddingRight: 80, width: 0, height: 30)
view.addSubview(areaTop)
areaTop.anchor(top: areaTxt.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 20, paddingLeft: 80, paddingBottom: 0, paddingRight: 80, width: 0, height: 30)
view.addSubview(lineLength)
lineLength.anchor(top: areaTop.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 20, paddingLeft: 80, paddingBottom: 0, paddingRight: 80, width: 0, height: 30)
view.addSubview(calculateButton)
calculateButton.anchor(top: lineLength.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 30, paddingLeft: 32, paddingBottom: 0, paddingRight: 32, width: 0, height: 50)
view.addSubview(movepitchline1)
movepitchline1.anchor(top: calculateButton.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 10, paddingLeft: 32, paddingBottom: 0, paddingRight: 32, width: 0, height: 40)
view.addSubview(movepitchline)
movepitchline.anchor(top: movepitchline1.bottomAnchor, left: view.leftAnchor, bottom: nil, right: view.rightAnchor, paddingTop: 10, paddingLeft: 32, paddingBottom: 0, paddingRight: 32, width: 0, height: 40)
}
// When keyboard displays the UIView shift up
#objc func keyboardWillShow(notification: NSNotification) {
guard let keyboardSize = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else {
// if keyboard size is not available for some reason, dont do anything
return
}
// move the root view up by the distance of keyboard height
self.view.frame.origin.y = 165 - keyboardSize.height
}
#objc func keyboarWillHide(notification: NSNotification){
self.view.frame.origin.y = 0
}
// select outside text box to dismiss selection
func configureNavigationBar() {
navigationController?.navigationBar.barTintColor = .appBlue
navigationController?.navigationBar.barStyle = .black
navigationItem.title = "Pass Pitch and Diameters"
navigationItem.leftBarButtonItem = UIBarButtonItem(image: #imageLiteral(resourceName: "Home_2x").withRenderingMode(.alwaysOriginal), style: .plain, target: self, action: #selector(handleDismiss))
}
}

How to overlay a view on the status bar in ios13

fileprivate lazy var netTipWindow:UIWindow = {
let window = UIWindow(frame: CGRect(x: 0, y: topMargins, width: UIScreenW, height: realheight))
window.backgroundColor = .clear
window.windowLevel = .alert
window.isHidden = false
window.rootViewController = UIViewController()
window.rootViewController?.view.addSubview(self)
frame = CGRect(x: 0, y: -(topMargins + realheight), width: UIScreenW, height: realheight)
return window
}()
My Code works well in ios 12, but it works like the picture.
Also, I tried this code, it makes no difference
fileprivate lazy var netTipWindow:UIWindow = {
let window = UIWindow(frame: CGRect(x: 0, y: topMargins, width: UIScreenW, height: realheight))
window.backgroundColor = .clear
window.windowLevel = .alert
window.isHidden = false
if #available(iOS 13, *) {
window.addSubview(self)
} else {
window.rootViewController = UIViewController()
window.rootViewController?.view.addSubview(self)
}
frame = CGRect(x: 0, y: -(topMargins + realheight), width: UIScreenW, height: realheight)
return window
}()
iOS 13 status bar
this code....
- (BOOL)prefersStatusBarHidden {
if (#available(iOS 13.0, *)) {
// safearea iPhone x, xr ..
if ([[[UIApplication sharedApplication] delegate] window].safeAreaInsets.top > 20.0) {
return NO;
}
else {
return YES;
}
}
else {
return NO;
}
}

My Swift framework not working in ObjectiveC but works fine in Swift

I have created a Swift framework that creating a button programmatically, and the action of the button is showing a webView and close it, my framework works fine in Swift project but in Objective C it just create button but it is not taking action and does not show my webView,
Note: I am getting the button configuration from server via JSON using SwiftyJSON
below is the my Swift Class in addition to SwiftyJSON in the framework project
import Foundation
import UIKit
import WebKit
#objc public class predictionButton : NSObject {
public override init(){
}
var buttonConfigApi = "XXXXXXXXX"
var buttonTextColor = String()
var buttonText = String()
var buttonBackgroundColor = String()
var buttonVisibility = Bool()
var indexURL = String()
var authURL = String()
var module = String()
var buttonAlignment = String()
var globalURL = String()
var webViewX = CGFloat()
var webViewY = CGFloat()
var webViewXiWidth = CGFloat()
var webViewHeight = CGFloat()
#objc public var globalView = UIView()
var parseFlag = Bool()
var buttonAlignmentValue = String()
#objc public func addButtonPredict(view: UIView, phone: String, token: String){
parseJSON()
sleep(5)
var phonTok = "{'a':\(phone),'b':\(token)}"
let utf8str = phonTok.data(using: String.Encoding.utf8)
let data = (phonTok).data(using: String.Encoding.utf8)
let base64 = data!.base64EncodedString(options: NSData.Base64EncodingOptions(rawValue: 0))
var finalURL = String()
self.globalView = view
finalURL = "\(self.indexURL)?d=\(base64)"
self.globalURL = finalURL
let button = UIButton(frame: buttonPosition(view: view, alignValue: buttonAlignment))
print((self.globalURL))
button.backgroundColor = hexStringToUIColor(hex: self.buttonBackgroundColor)
print("global color value \(buttonBackgroundColor)")
button.setTitle("\(self.buttonText)", for: .normal)
button.setTitleColor(hexStringToUIColor(hex: self.buttonTextColor), for: .normal)
let buttonFontSize = 15
let buttonTitleSize = (buttonText as NSString).size(withAttributes: [NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: CGFloat(buttonFontSize + 1))])
button.frame.size.height = buttonTitleSize.height * 2
button.frame.size.width = buttonTitleSize.width * 1.5
view.addSubview(button)
button.tag = 5
button.addTarget(self, action: #selector(nest), for: .touchUpInside)
}
#objc func nest (){
let frame = webViewposition(view: self.globalView)
let webView = WKWebView(frame: frame)
webView.load(NSURLRequest(url: NSURL(string: globalURL)! as URL) as URLRequest)
webView.contentMode = .scaleAspectFit
webView.tag = 100
if let viewWithTag = self.globalView.viewWithTag(100) {
viewWithTag.removeFromSuperview()
}else{
print("No!")
self.globalView.addSubview(webView)
}
}
#objc public func parseJSON(){
print("flag")
let requestURL: NSURL = NSURL(string: buttonConfigApi)!
let urlRequest: URLRequest = URLRequest(url: requestURL as URL)
let session = URLSession.shared
let task = session.dataTask(with: urlRequest as URLRequest) {
(data, response, error) -> Void in
if data != nil {
do
{
let readableJSON = try JSON(data: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
let Name = readableJSON["data"]["buttonText"].stringValue as String!
let buttonTextColor = readableJSON["data"]["buttonTextColorCode"].stringValue as String!
let buttonBackgroundColorCode = readableJSON["data"]["buttonBackgroundColorCode"].stringValue as String!
let visibility = readableJSON["data"]["visibility"].boolValue
let indexURL = readableJSON["data"]["indexURL"].stringValue as String!
let authURL = readableJSON["data"]["authURL"].stringValue as String!
let module = readableJSON["data"]["module"].stringValue as String!
let alignment = readableJSON["data"]["alignment"].stringValue as String!
self.buttonText = Name!
self.buttonTextColor = buttonTextColor!
self.buttonBackgroundColor = buttonBackgroundColorCode!
self.buttonAlignment = self.alignText(text: alignment!)
self.indexURL = indexURL!
self.authURL = authURL!
self.module = module!
print("\(Name!) \n \(buttonTextColor!) \n \(buttonBackgroundColorCode!) \n \(indexURL!) \n \(alignment!)")
print("done")
print("Color value:\(buttonBackgroundColorCode!)")
} catch {
print(error)
}
}
}
task.resume()
}
#objc func alignText (text: String) -> String {
var alignText = String()
let newString = text.replacingOccurrences(of: "_", with: "",
options: .literal, range: nil)
return newString.lowercased()
}
#objc func hexStringToUIColor (hex:String) -> UIColor {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
print("became gray")
return UIColor.gray
}
var rgbValue:UInt32 = 0
Scanner(string: cString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
#objc func webViewposition(view: UIView) -> CGRect {
var frame = CGRect()
if UIDevice.current.orientation == UIDeviceOrientation.landscapeLeft {
frame = CGRect(x: (view.frame.width) - (view.frame.width / 4) - 120 , y: 20 , width: view.frame.width / 3 , height: view.frame.height - 60 )
} else if UIDevice.current.orientation == UIDeviceOrientation.landscapeRight {
frame = CGRect(x: (view.frame.width) - (view.frame.width / 4) - 120, y: 20 , width: view.frame.width / 3 , height: view.frame.height - 60 )
} else if UIDevice.current.orientation == UIDeviceOrientation.portrait {
frame = CGRect(x: 0, y: 110, width: view.frame.width, height: view.frame.height - 60 )
} else if UIDevice.current.orientation == UIDeviceOrientation.portraitUpsideDown {
frame = CGRect(x: 0, y: 100, width: view.frame.width, height: view.frame.height - 60 )
}
return frame
}
#objc func buttonPosition(view: UIView, alignValue: String)-> CGRect {
var position = CGRect()
switch (alignValue){
case "lefttop":
print("button top left")
position = CGRect(x: 25, y: 50, width: 100, height: 100)
case "righttop":
print("button top right")
position = CGRect(x: view.frame.width - 150, y: 50, width: 100, height: 100)
case "letbottom":
print("button bottom left")
position = CGRect(x: 25, y: view.frame.height - 150, width: 100, height: 100)
case "rightbottom":
print("button bottom right")
position = CGRect(x: view.frame.width - 25, y: view.frame.height - 150, width: 100, height: 100)
default:
position = CGRect(x: 25, y: 50, width: 100, height: 100)
}
return position
}
}
extension UIColor {
convenience init(red: Int, green: Int, blue: Int) {
assert(red >= 0 && red <= 255, "Invalid red component")
assert(green >= 0 && green <= 255, "Invalid green component")
assert(blue >= 0 && blue <= 255, "Invalid blue component")
self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) /
255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
}
convenience init(rgb: Int) {
self.init(
red: (rgb >> 16) & 0xFF,
green: (rgb >> 8) & 0xFF,
blue: rgb & 0xFF
)
}
}
extension String {
var numberValue:NSNumber? {
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter.number(from: self)
}
}
and I have created a Objective-C and add the built framework in it and its .m file code is below :
#import "ViewController.h"
#import myFrameWork;
#import <myFrameWork/myFrameWork-Swift.h>
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
predictionButton *btn = [[predictionButton alloc] init];
[btn addButtonPredictWithView:self.view phone:#"XXXXXXX"
token:#"XXXXXXXXXXXXXXXXXXXXXXXXXXX"];
}
#end
Note: this framework works fine in Swift project
Here is working swift code:
import UIKit
import myFrameWork
import WebKit
class ViewController: UIViewController {
var button = predictionButton()
override func viewDidLoad() {
super.viewDidLoad()
button.addButtonPredict(view: self.view, phone: "XXXXXXXXXX", token: "XXXXXXXXXXXXXXXXXXXXXXXXX")
}