我曾经能够生成NSAttributedString
并使用UITextView
类typingAttributes
设置[String: Any]
[String: Any]
类型[NSAttributedStringKey: Any]
NSAttributedString
1}}。自iOS 11以来,我必须将UITextView
属性更改为[String: Any]
属性才能生成def if_powerof_3(n):
var = n
power = 0
while var>1:
if var%3 ==0:
var=var/3
power=power+1
else:
return "{} is not a power of 3".format(n)
return "{} is a power of 3".format(n)
print (if_powerof_3(27))
,但import fileinput, csv
mark = input("mark:")
username = input("username:")
with open("marksh.txt", "r+") as f:
lines = f.readlines()
for line in lines:
if username in line:
username, markeasy, markmedium , markhard = line.strip().split("\t")
with open("marksh.txt", "a")as f:
f.write(username + " " + mark + " " + markmedium+ " " + markhard)
with open("marksh.txt","r") as f:
lines = f.readlines()
finduser = input("username:")
for line in lines:
if finduser in line:
username, markeasy, markmedium , markhard = line.strip().split("\t")
print((username) + (markeasy))
仍然属于{{1}}类型。为什么呢?
答案 0 :(得分:0)
不确定为什么它不是[NSAttributedStringKey: Any]
但是你可以像这样转换它
func ConvertToTypingAttributes(_ attr: [NSAttributedStringKey: Any]) -> [String: Any] {
var result = [String: Any]()
for (k,v) in attr {
result[k.rawValue] = v
}
return result
}
用法:
var txtView = UITextView()
let p: [NSAttributedStringKey: Any] = [NSAttributedStringKey.backgroundColor: UIColor.green]
txtView.typingAttributes = ConvertToTypingAttributes(p)