Skip to content

Instantly share code, notes, and snippets.

View mahmudahsan's full-sized avatar

Mahmud Ahsan mahmudahsan

View GitHub Profile
import SwiftUI
import Combine
class AppState: ObservableObject {
func reloadDashboard() {
(UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate)?.reloadDashboard()
}
}
var window: UIWindow?
var contentView: ContentView?
var appState: AppState?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
self.window = window
reloadDashboard()
}
struct ContentView: View {
var body: some View {
HStack {
Text("Gender")
.font(Font.headline)
RadioButtonGroups { selected in
print("Selected Gender is: \(selected)")
}
}.padding()
}
//MARK:- Group of Radio Buttons
enum Gender: String {
case male = "Male"
case female = "Female"
}
struct RadioButtonGroups: View {
let callback: (String) -> ()
@State var selectedId: String = ""
import SwiftUI
//MARK:- Single Radio Button Field
struct RadioButtonField: View {
let id: String
let label: String
let size: CGFloat
let color: Color
let textSize: CGFloat
struct GradientText: View {
let title: String
let colors = Gradient(colors: [Color.hexStringToColor(hex: "#FF0000"),
Color.hexStringToColor(hex: "#40B482")])
var body: some View {
RadialGradient(gradient: colors,
center: .center,
startRadius: 0,
endRadius: 300)
@mahmudahsan
mahmudahsan / swiftui_color_from_hex.swift
Created February 27, 2020 04:42
SwiftUI how to create color from hex value
extension Color {
static func hexStringToColor (hex:String, opacity: Double = 1.0) -> Color {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
return Color.gray
}
var rgbValue:UInt64 = 0
@mahmudahsan
mahmudahsan / swiftui_gradient_text1.swift
Created February 27, 2020 04:40
SwiftUI How to create a gradient text
import SwiftUI
extension Color {
static func hexStringToColor (hex:String, opacity: Double = 1.0) -> Color {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) != 6) {
return Color.gray
@mahmudahsan
mahmudahsan / obj-c.m
Last active February 7, 2020 05:26
Objective-C Code
const char *sqlStatement = [query UTF8String];
sqlite3_stmt *compiledStatement;
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
// Loop through the results and add them to the feeds array
while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
// Read the data from the result row
NSString *word = [NSString stringWithUTF8String:(char *)sqlite3_column_tcompiledStatement,
[arrayWords addObject:word];
}
}
@mahmudahsan
mahmudahsan / ios_detect.h
Created September 26, 2017 11:40
iPhone X and other iOS device detection by Swift and Objective-C
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))