I have added the Glow colour to text with the help of shadow using custom class code below in SwiftUI.
Want to achieve:-
Output:-
Code:-
struct ContentView: View {
var body: some View {
ZStack {
Text("Hello world!")
.underline()
.font(Font.system(size: 26))
.padding(.bottom, 80).shadow(color: Color(UIColor(displayP3Red: 96/255, green: 252/255, blue: 255/255, alpha: 2)), radius: 3, x: 1, y: 1)
}
}
}
Question: Can someone please explain to me how to set same glow colour on text, I've tried with above code but no results yet.
Can someone please explain to me How to get Progress?
Any help would be greatly appreciated.
Thanks in advance.
Try this:-
struct CustomLabelModify: View {
var body: some View {
ZStack{
Color.black
Group{
Text("Following")
.addGlowEffect(color1: Color(Color.RGBColorSpace.sRGB, red: 96/255, green: 252/255, blue: 255/255, opacity: 1), color2: Color(Color.RGBColorSpace.sRGB, red: 44/255, green: 158/255, blue: 238/255, opacity: 1), color3: Color(Color.RGBColorSpace.sRGB, red: 0/255, green: 129/255, blue: 255/255, opacity: 1))
}
}
}
}
extension View {
func addGlowEffect(color1:Color, color2:Color, color3:Color) -> some View {
self
.foregroundColor(Color(hue: 0.5, saturation: 0.8, brightness: 1))
.background {
self
.foregroundColor(color1).blur(radius: 0).brightness(0.8)
}
.background {
self
.foregroundColor(color2).blur(radius: 4).brightness(0.35)
}
.background {
self
.foregroundColor(color3).blur(radius: 2).brightness(0.35)
}
.background {
self
.foregroundColor(color3).blur(radius: 12).brightness(0.35)
}
}
}
Related
I have a format problem. How I want is the 2nd picture but for some reason, my view starts a little bit lower. You can see the gap between the pictures. I want to solve this problem without offset. Might be because of .navigationBarHidden(true) but I do not want navigation bar.
I added NavigationView to my code because I have a button down-right to add a new task.
Plus for some reason, this button is not clickable. Would be good if you give a hand to that problem.
import SwiftUI
struct TaskListView: View {
#State private(set) var data = ""
#State var isSettings: Bool = false
#State var isSaved: Bool = false
var body: some View {
NavigationView {
ZStack {
Color(#colorLiteral(red: 0.9333333333, green: 0.9450980392, blue: 0.9882352941, alpha: 1)).edgesIgnoringSafeArea(.all)
VStack {
TopBar()
HStack {
CustomTextField(data: $data, tFtext: "Find task", tFImage: "magnifyingglass")
Button(action: {
self.isSettings.toggle()
}, label: {
ZStack {
RoundedRectangle(cornerRadius: 15)
.frame(width: 50, height: 50, alignment: .center)
.foregroundColor(Color(#colorLiteral(red: 0.4274509804, green: 0.2196078431, blue: 1, alpha: 1)))
Image("buttonImage")
.resizable()
.frame(width: 30, height: 30, alignment: .center)
}
.padding(.horizontal, 15)
})
}
CustomSegmentedView()
ZStack {
TaskFrameView()
Button( action: {
self.isSaved.toggle()
}, label: {
ZStack {
RoundedRectangle(cornerRadius: 20)
.foregroundColor(Color(#colorLiteral(red: 1, green: 0.7137254902, blue: 0.2196078431, alpha: 1)))
Text("+")
.foregroundColor(.white)
.font(.title)
.fontWeight(.bold)
}
.frame(width: 40, height: 40)
.offset(x: 150, y: 220)
})
NavigationLink(
destination: NewTaskView(),
isActive: $isSaved,
label: {
Text("")
})
}
}
}
Spacer()
}
.navigationBarHidden(true)
}
}
struct TopBar: View {
var body: some View {
HStack {
Image("avatar")
.resizable()
.frame(width: 100, height: 100)
VStack(alignment: .leading){
DateView()
.font(Font.custom("SFCompactDisplay", size: 20))
.foregroundColor(.gray)
.padding(.vertical, 5)
Text("Hi, Random")
.font(Font.custom("SFCompactDisplay", size: 20))
}
Image(systemName: "ellipsis")
}
}
}
It is navigation view bar. The navigationBarHidden modifier should be inside NavigationView, like
}
.navigationBarHidden(true) // << here !!
Spacer()
} // end of NavigationView
I've been trying to program something with swiftui recently,
it's difficult, how can I transfer the value of the picker into the
text field, I'm desperate!
and why can I not work with the value $ khValue directly as in the text field?
I've already spent hours searching the internet… I haven't found anything yet, swiftUI is completely different from swift
import SwiftUI
struct KH_aus_Co2: View {
#State private var kh_Picker : String = ""
#State private var ph_Picker: String = ""
var kh_vol = [Int](0..<21)
var ph_vol = [Int](0..<10)
init(){
UITableView.appearance().backgroundColor = .clear
}
#State private var khWert: String = ""
#State private var phWert: String = ""
#State private var phco2Wert: String = ""
var calculation: String {
guard khWert.isEmpty == false, phWert.isEmpty == false else { return "" }
guard let kh = Double(khWert), let ph = Double(phWert) else { return "Error" }
let product = kh/2.8 * pow(10,7.90-ph)
return String(format: "%.2f", product)
}
var body: some View {
VStack() {
Text("Co2 = \(calculation) mg/ltr")
.font(.largeTitle)
.multilineTextAlignment(.center)
.foregroundColor(Color.green)
.frame(width: 300, height: 60, alignment: .center)
.border(Color.green)
.frame(minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity, alignment: .center)
HStack {
TextField("KH Wert", text: $khWert)
.border(Color.green)
.frame(width: 120, height: 70, alignment: .center)
.textFieldStyle(RoundedBorderTextFieldStyle())
// .textContentType(.oneTimeCode)
.keyboardType(.numberPad)
TextField("PH Wert", text: $phWert)
.border(Color.green)
.frame(width: 120, height: 70, alignment: .center)
.textFieldStyle(RoundedBorderTextFieldStyle())
// .textContentType(.oneTimeCode)
.keyboardType(.numberPad)
}
GeometryReader { geometry in
HStack {
Picker(selection: self.$kh_Picker, label: Text("")) {
ForEach(0 ..< self.kh_vol.count) { index in
Text("\(self.kh_vol[index])").tag(index)
//
}
}
.frame(width: geometry.size.width/3, height: 100, alignment: .center) .clipped()
Picker(selection: self.$ph_Picker, label: Text("")) {
ForEach(0 ..< self.ph_vol.count) { index in
Text("\(self.ph_vol[index])").tag(index)
}
}
.frame(width: geometry.size.width/3, height: 100, alignment: .center) .clipped()
}
}
}
.navigationBarTitle(Text("Co2 aus KH & PH"))
.font(/*#START_MENU_TOKEN#*/.title/*#END_MENU_TOKEN#*/)
}
}
struct KH_aus_Co2_Previews: PreviewProvider {
static var previews: some View {
Co2_aus_KH()
}
}
big thanks for your help
Jürgen....................................
If I understand you correctly, you want the pickers to update the values in the textfields. If so, then you want to bind the same value to the picker that the textfield is using. Since that value is a String, you will want to use String values in your picker.
Use .map(String.init) to turn the kh_vol and ph_vol ranges into arrays of String, and use \.self as the id::
Picker(selection: self.$khWert, label: Text("")) {
ForEach(self.kh_vol.map(String.init), id: \.self) { index in
Text(index)
}
}
.frame(width: geometry.size.width/3, height: 100, alignment: .center)
.clipped()
Picker(selection: self.$phWert, label: Text("")) {
ForEach(self.ph_vol.map(String.init), id: \.self) { index in
Text(index)
}
}
.frame(width: geometry.size.width/3, height: 100, alignment: .center)
.clipped()
I am drawing a line with Path, and on that line I want to have a circle if I play around I can get the circle on the line of course. However I do not understand why this code does not put the circle on the line:
struct CircleOnLineView: View {
func createCirle() -> some View {
return Circle().fill(Color.blue)
}
var body: some View {
GeometryReader { geometry in
ZStack {
Path { path in
path.move(to: CGPoint(x: 0, y: geometry.size.height / 2))
path.addLine(to: CGPoint(x: geometry.size.width, y: geometry.size.height / 2))
}
.stroke(Color.gray, lineWidth: 3)
Circle()
.fill(Color.blue)
.position(CGPoint(x: 0 , y: geometry.size.height / 2))
.frame(width: 5, height: 5)
}
}
}
}
Order of modifiers in this case is important. Here is how it is expected (1st - made size of shape, 2nd - position it):
Circle()
.fill(Color.blue)
.frame(width: 5, height: 5)
.position(CGPoint(x: 0 , y: geometry.size.height / 2))
I'm using the glify plugin for Leaflet, and can't for the life of me figure out how to set the color of my points to a function.
This works fine:
L.glify.points({
data: data,
map: map,
opacity: 1,
size: 10,
color: 'red',
However this returns all black points:
L.glify.points({
data: data,
map: map,
opacity: 1,
size: 10,
color: function(){
if ( 1 > 0 ){ return 'red';}else{return 'blue';}
},
Does anyone have any idea what I need to do here?
figured it out, needs to be formatted like this:
color: function(){
if (1 > 0){
return {
r: 0,
g: .51,
b: .1
};
}else{
return {
r: 30,
g: 1,
b: 2
};
}
},
You need to convert your hex color code into rgb form using below function
function fromHex(hex) {
if (hex.length < 6) return null;
hex = hex.toLowerCase();
if (hex[0] === '#') {
hex = hex.substring(1, hex.length);
}
var r = parseInt(hex[0] + hex[1], 16),
g = parseInt(hex[2] + hex[3], 16),
b = parseInt(hex[4] + hex[5], 16);
return {
r: r / 255,
g: g / 255,
b: b / 255
};
}
and then return it like this :
L.glify.points({
data: data,
map: map,
opacity: 1,
size: 10,
color: function(){
if ( 1 > 0 ){
return fromHex("#FF0000");
}else{
return fromHex("#0000FF");
}
}
});
I recently switched from using PaintCode 2 to PaintCode 3, I am using it together with xCode/Swift.
I noticed however, that all my image generating functions not behave differently. They seam to standard addopt cap insets.
As an example below you can find one canvas "ViewMissingImage", and how its configured in PaintCode (2 or 3 its identical).
Code generated via PaintCode 2
public class func imageOfViewMissingImage(frame frame: CGRect = CGRect(x: 6, y: 5, width: 109, height: 109)) -> UIImage {
UIGraphicsBeginImageContextWithOptions(frame.size, false, 0)
PaintCode.drawViewMissingImage(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height))
let imageOfViewMissingImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return imageOfViewMissingImage
}
Code generated via PaintCode 3
public dynamic class func imageOfViewMissingImage(imageSize imageSize: CGSize = CGSize(width: 109, height: 109)) -> UIImage {
UIGraphicsBeginImageContextWithOptions(imageSize, false, 0)
PaintCode.drawViewMissingImage(frame: CGRect(x: 0, y: 0, width: imageSize.width, height: imageSize.height))
let imageOfViewMissingImage = UIGraphicsGetImageFromCurrentImageContext()!.resizableImageWithCapInsets(UIEdgeInsetsZero, resizingMode: .Tile)
UIGraphicsEndImageContext()
return imageOfViewMissingImage
}
I think that the PaintCode 2 never used the capp insets, maybe it was a bug?
I do not want these cap insets, how can I get rid of them?
The solution is straightforward:
Put the Cap Inset on "Stretch" instead of tile in PaintCode UI!