Don't show hexagram in label how font IOS < 13 swift 4 - swift4

I don't understand why label not show my hexagram. Simulator IOS < 13 not show, IOS > 13 all ok.
I try change font to system but that not help. That my code.
let hierogliph: UILabel = {
let hierogliph = UILabel()
hierogliph.text = "䷄"
hierogliph.textColor = #colorLiteral(red: 0.2129859924, green: 0.161139518, blue: 0.1228835955, alpha: 1)
hierogliph.minimumScaleFactor = 0.5
hierogliph.adjustsFontSizeToFitWidth = true
hierogliph.textAlignment = .center
hierogliph.font = UIFont(name: "IM_FELL_Double_Pica_SC", size: 100)
hierogliph.translatesAutoresizingMaskIntoConstraints = false
return hierogliph
}()
Foto Simulator IOS 12.2 and IOS 13.3
enter image description here
Thank for help.

Found answer. Found a font that supports hexagram - DejaVuSans. Add font to project

Related

Can't set the same color for background and border in UISegmentedControl

I am trying to customize my segmented control with Swift, but I have run into a problem. I set the same color (e.g. UIColor.red) for border and background, but they look different. My code is:
segmentedControl.layer.cornerRadius = 12
segmentedControl.layer.borderWidth = 2
segmentedControl.layer.borderColor = UIColor.red.cgColor
segmentedControl.layer.masksToBounds = true
segmentedControl.backgroundColor = .red
Maybe someone knows how can I fix it?
Try setting the tintColor and selectedSegmentTintColor:
segmentedControl.tintColor = .white
segmentedControl.selectedSegmentTintColor = .white

How should I solve this error: Thread 1: EXC_RESOURCE RESOURCE_TYPE_MEMORY (limit=650 MB, unused=0x0)?

I am trying to run my app which uses this GitHub project: https://github.com/PaoloCuscela/Cards/wiki/Overview
But when I run my app on my iPhone 6, it crashes and gives me the error in the title.
I've written 28 of these in my viewDidLoad function and the app runs fine on the simulator.
let tennisCard = CardHighlight(frame: CGRect(x: 67, y: 3362, width: 250, height: 300))
tennisCard.title = "Exercise 11"
tennisCard.itemTitle = "Tennis"
tennisCard.backgroundColor = UIColor(red: 0/255, green: 255/255, blue: 79/255, alpha: 1)
tennisCard.buttonText = "See"
tennisCard.itemSubtitle = ""
tennisCard.tintColor = UIColor.black
tennisCard.textColor = UIColor.black
tennisCard.icon = UIImage(named: "Tennis")
let tennisVC = storyboard?.instantiateViewController(withIdentifier: "TennisCardContent")
tennisCard.shouldPresent(tennisVC, from: self)
scrollView.addSubview(tennisCard)
It seems like your app uses to much resources.
First of all, check if your assets have big file sizes, and if that is the case resize them to a lower resolution.
Also loading all of these (mostly hidden below the visible area) views into the scroll view at once is very memory inefficient. Try using a table view or collection view that only loads these views when visible. This could also help you get rid of code duplication

Different UIFont sizes for different iOS devices in Swift

I'm developing swift based iOS application for iPhone family. My application supports all devices start from iPhone 4s to iPhone X. Labels appears bigger in smaller devices like iPhone 4s as I added bigger font size for high end devices. Can someone help me on how to scale the font according to device. I tried size classes with compact/regular width and compact/regular height but none of them helped me. Your help is very much appreciated
Programmatically
Without using the storyboard I have the approach to simply change the font size depending on the screen width like so:
func dynamicFontSize(_ FontSize: CGFloat) -> CGFloat {
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * FontSize
return calculatedFontSize
}
and can be used as:
myLabel.font = UIFont(name: "Helvetica", size: dynamicFontSize(20))
Note that in the dynamicFontSize function the number 375 is simply the basis for the font size calculation, because I usually test my app on iPhone 8 (i.e. font size 18 is actually 18 on an iPhone 8 due to its actual width of 375). This number can be altered to your liking.
Storyboard
If you insist on using storyboard, you can instead create a new swift file subclassing UILabel and use an #IBInspectable like so:
import UIKit
class UILabelFontClass: UILabel {
#IBInspectable var DynamicFontSize: CGFloat = 0 {
didSet {
overrideFontSize(FontSize: DynamicFontSize)
}
}
func overrideFontSize(FontSize: CGFloat){
let fontName = self.font.fontName
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * FontSize
self.font = UIFont(name: fontName, size: calculatedFontSize)
}
}
Inside storyboard subclass UILabelFontClass to your label:
And now in the Attributes inspector, you can set the font size:
You can try label hight according to view in storyboard .
with this image reference i done with iPhone 5s screen size and give label hight equal to hight in multiplier 30/554
Instead of making different class for UILabel. You can make UILabel Extension and use this IBDesignable Solution to set values from Storyboard.
Here Base width is 375pt
extension UILabel{
#IBInspectable
var scaleSize: CGFloat {
set {
let fontName = self.font.fontName
let screenWidth = UIScreen.main.bounds.size.width
let calculatedFontSize = screenWidth / 375 * newValue
self.font = UIFont(name: fontName, size: calculatedFontSize)
}
get {
return self.scaleSize
}
}
}

Header Logo is wrong size on Swift 4 / XCode 9 / iOS 11

I just updated XCode to version 9, and when running my project with no major changes, the title logo has increased its size to fill the header. Before upgrading, its size covered around 50% of the navigation bar as I intended to.
The code where I position the logo is the following:
//Logo on NavBar
let logo = UIImage(named: "logo.png")
let imageView = UIImageView(image:logo)
imageView.height = (self.navigationController?.navigationBar.height)! - 25
imageView.contentMode = .scaleAspectFit
self.navigationItem.titleView = imageView
Here's how the logo used to (and it's supposed to) look:
And after the XCode update, this is how it looks:
Any ideas of why this might be happening?
I've had the same problem - just appearing in iOS 11.
So i've set a height and a width constraint for the imageview programmatically.
imageView.widthAnchor.constraint(equalToConstant: YOUR_WIDTH).isActive = true
imageView.heightAnchor.constraint(equalToConstant: YOUR_HEIGHT).isActive = true
To make the same in iOS 11, add a subView in the titleView and resize it as you like.
let imagen = UIImageView(frame: CGRect(x: -view.view.frame.width/3, y: -(view.navigationController?.navigationBar.frame.height)! / 2, width: view.view.frame.width/1.5 , height: (view.navigationController?.navigationBar.frame.height)!))
imagen.image = #imageLiteral(resourceName: "logo")
view.navigationItem.titleView = UIView()
view.navigationItem.titleView?.addSubview(imagen)

UIView background color in Swift

Is there a way to set the UIView background color with Swift?
I know that in Objective-C, you would use self.view.backgroundColor = [UIColor redColor];, but that does not work the same way in Swift. I have looked around and because Swift is only about a week old, I cannot find an answer.
Does anyone have any suggestions?
self.view.backgroundColor = UIColor.redColor()
In Swift 3:
self.view.backgroundColor = UIColor.red
Try This, It worked like a charm! for me,
The simplest way to add backgroundColor programmatically by using ColorLiteral.
You need to add the property ColorLiteral, Xcode will prompt you with a whole list of colors in which you can choose any color. The advantage of doing this is we use lesser code, add HEX values or RGB. You will also get the recently used colors from the storyboard.
Follow steps ,
1) Add below line of code in viewDidLoad() ,
self.view.backgroundColor = ColorLiteral
and clicked on enter button .
2) Display square box next to =
3) When Clicked on Square Box Xcode will prompt you with a whole list of colors which you can choose any colors also you can set HEX values or RGB
4) You can successfully set the colors .
Hope this will help some one to set backgroundColor in different ways.
I see that this question is solved, but, I want to add some information than can help someone.
if you want use hex to set background color, I found this function and work:
func UIColorFromHex(rgbValue:UInt32, alpha:Double=1.0)->UIColor {
let red = CGFloat((rgbValue & 0xFF0000) >> 16)/256.0
let green = CGFloat((rgbValue & 0xFF00) >> 8)/256.0
let blue = CGFloat(rgbValue & 0xFF)/256.0
return UIColor(red:red, green:green, blue:blue, alpha:CGFloat(alpha))
}
I use this function as follows:
view.backgroundColor = UIColorFromHex(0x323232,alpha: 1)
some times you must use self:
self.view.backgroundColor = UIColorFromHex(0x323232,alpha: 1)
Well that was it, I hope it helps someone .
sorry for my bad english.
this work on iOS 7.1+
You can use the line below which goes into a closure (viewDidLoad, didLayOutSubViews, etc):
self.view.backgroundColor = .redColor()
EDIT Swift 3:
view.backgroundColor = .red
You can use this extension as an alternative if you're dealing with RGB value.
extension UIColor {
static func rgb(red: CGFloat, green: CGFloat, blue: CGFloat) -> UIColor {
return UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 1)
}
}
In Swift 4, just as simple as Swift 3:
self.view.backgroundColor = UIColor.brown
The response by #Miknash and #wolfgang gutierrez barrera was helpful to me. Only difference was I had to add rgbValue: to the function call.
UIColorFromHex(rgbValue: 0xA6D632,alpha: 1 ) like so
If you want to set your custom RGB color try this:
self.view.backgroundColor = UIColor(red: 20/255.0, green: 106/255.0, blue: 93/255.0, alpha: 1)
Don't forget to keep /255.0 for every color
In the Xcode 13, the shortcut ColorLiteral does not work anymore.
Now, you have to use this shortcut: #colorLiteral(