刚刚下载了新的xCode 10.0,并且发现旧的statusBarStyle自iOS 9.0以来已被弃用.
警告: Setter for 'statusBarStyle' was deprecated in iOS 9.0: Use -[UIViewController preferredStatusBarStyle]
不推荐的代码:
UIApplication.shared.statusBarStyle = .default
我尝试过使用self.preferredStatusBarStyle,但发现该物业只是一个吸气剂.所以任何人都知道如何设置statusBarStyle?
我想在一个函数中更改statusBarStyle,用户可以在不同的主题之间切换.例如:
func changeStatusBar(toDarkMode: Bool) {
if toDarkMode {
// Set to light statusBarStyle
} else {
// Set to default
}
}
Run Code Online (Sandbox Code Playgroud) 我有两页的tiff图像.当我将文件转换为jpg格式时,我丢失了第二页.有没有办法将tiff文件上的两个图像放入一个jpg文件中.因为tiff文件太大我不得不减小它们的大小.有没有办法以编程方式减少tiff文件大小?它也可以解决我的问题.
我正试图在UILabel中设置一些插件.它工作得很好,但现在
UIEdgeInsetsInsetRect已被替换,CGRect.inset(by:)我无法找到如何解决这个问题.
当我试图使用CGRect.inset(by:)我的插图,然后我收到UIEdgeInsets不可转换的消息CGRect.
class TagLabel: UILabel {
override func draw(_ rect: CGRect) {
let inset = UIEdgeInsets(top: -2, left: 2, bottom: -2, right: 2)
super.drawText(in: CGRect.insetBy(inset))
// super.drawText(in: UIEdgeInsetsInsetRect(rect, inset)) // Old code
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道如何设置UILabel的插图?
我试图更改标题fontSize中的UIAlertController,但我不能管理如何我设置NSMutableAttributedString的title-属性。
所以我一直在NSMutableAttributedString使用以下代码创建:
let title = NSMutableAttributedString(string: user.fullName)
let range = NSRange(location: 0, length: title.length)
title.addAttribute(NSAttributedStringKey.font, value: UIFont.TextStyle.largeTitle, range: range)
Run Code Online (Sandbox Code Playgroud)
现在对我来说棘手的部分是如何弄清楚如何将新标题设置为UIAlertController,因为它需要一个String?值。
我环顾四周,发现UILabel在呈现UIAlertController. 但是如何使用我自己的自定义覆盖title-property ?UIAlertControllerUILabel
present(myUIAlertController, animated: true) {
// Creating the UILabel depending on string length
// Set the NSMutableAttributedString value to the custom UILabel and override title property.
}
Run Code Online (Sandbox Code Playgroud)
或者也许有更简单的方法来解决这个问题?
nsmutableattributedstring swift uialertviewcontroller swift4
只是弄清楚如何在一个文本中实现多行文本Text。似乎的Text默认值与UILabel(一行)相同,但是我找不到符合此条件的任何函数。
struct ContentView : View {
var body: some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("Avocado Toast").font(.system(size: 24))
}
// This Text does cut, and I wonder how I can achieve multiple rows
Text("Ingredients: Avocado, Almond Butter, Bread")
.font(.system(size: 20))
}
}
}
Run Code Online (Sandbox Code Playgroud)
.lineLimit(X),做到了。但是,例如,可以不设置特定的数量。只有0?
我想弄清楚如何\n用最多两个中断替换多个中断 ( )。我使用trimmingCharacters(in:)删除字符串周围的所有空格和新行,但我不知道如何删除字符串中的空格,或者说:我怎么能替换超过 2 个中断最多2次休息?
如果用户在 textView 中写入单词之间有空格,则字符串将为:
"Hello
I like coffee"
Run Code Online (Sandbox Code Playgroud)
"Hello
I like coffee"
Run Code Online (Sandbox Code Playgroud) 我最近一直在关注一个指南,并注意到他们写了一条我以前从未见过的线,我不知道它叫什么,以及它是如何工作的.
let title: String = isPaused ? "Start" : "Pause"
因此该物业isPaused具有Bool的类型,但问号代表什么?这是一种"转换"语句,当值可能是Start或Pause?
最后一个问题,这种操作甚至被称为什么?
谢谢!