Files
Woka_Native_iOS/WOKA/Helpers/UIElements Helper/CustomizableSegmentControl.swift
BilalKhanWDI 0e921c3113 - Handled the star and moon to show only at the night time.
- Added a star above the grass and added it to the animation.
- Woke Client call 1:15 - 1:40
- Added Sidebar theme clicks and added userdefaults with checks for default loading. Also added to logout
- Handled the Theme change from sidebar, also handled the default theme selected and loading it at the time of startup
- Fixed issue of sidebar showing up, left side blacktint was not coming. It was the issue of ViewLifeCycle
- Theme 2  Explore woka items size ratio updated for auto layouts
- Worked on RootView Navigation.
2024-05-27 19:42:56 +05:30

67 lines
2.4 KiB
Swift

//
// CustomizableSegmentControl.swift
// WOKA
//
// Created by MacBook Pro on 27/05/24.
//
import UIKit
class CustomizableSegmentControl: UISegmentedControl {
private(set) lazy var radius:CGFloat = bounds.height / 2
private let segmentInset: CGFloat = 5
private let segmentImage: UIImage? = UIImage(color: UIColor.white)
override init(items: [Any]?) {
super.init(items: items)
selectedSegmentIndex = 0
}
required init?(coder: NSCoder) {
// fatalError("init(coder:) has not been implemented")
super.init(coder: coder)
}
override func layoutSubviews(){
super.layoutSubviews()
self.backgroundColor = #colorLiteral(red: 0.01960784314, green: 0, blue: 0.2196078431, alpha: 1)
// selected option color
self.setTitleTextAttributes([.foregroundColor: UIColor.black, .font : UIFont.systemFont(ofSize: 16, weight: .heavy)], for: .selected)
// color of other options
self.setTitleTextAttributes([.foregroundColor: UIColor.white, .font : UIFont.systemFont(ofSize: 16, weight: .heavy)], for: .normal)
//background
layer.cornerRadius = radius
//foreground
let foregroundIndex = numberOfSegments
if subviews.indices.contains(foregroundIndex), let foregroundImageView = subviews[foregroundIndex] as? UIImageView{
foregroundImageView.bounds = foregroundImageView.bounds.insetBy(dx: segmentInset, dy: segmentInset)
foregroundImageView.image = segmentImage //substitute with our own colored image
foregroundImageView.layer.removeAnimation(forKey: "SelectionBounds") //this removes the weird scaling animation!
foregroundImageView.layer.masksToBounds = true
foregroundImageView.layer.cornerRadius = foregroundImageView.bounds.height/2
}
}
}
extension UIImage{
//creates a UIImage given a UIColor
public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
let rect = CGRect(origin: .zero, size: size)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
color.setFill()
UIRectFill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
guard let cgImage = image?.cgImage else { return nil }
self.init(cgImage: cgImage)
}
}