我的项目中有一个 TabBar,当用户选择项目时,该项目将禁用,但颜色也会改变!我希望颜色与我使用的 TabBar 中其他项目的颜色相同
item.isEnabled = false
Run Code Online (Sandbox Code Playgroud)
用于禁用项目,但此处的代码不适用于该项目
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.tabBar.barTintColor = UIColor.init(red: 126/255, green: 0/255, blue: 64/255, alpha: 1.0)
if #available(iOS 10.0, *) {
self.tabBar.unselectedItemTintColor = UIColor.white
self.tabBar.unselectedItemTintColor = UIColor.white
} else {
// Fallback on earlier versions
}
UITabBar.appearance().tintColor = UIColor.white
}
Run Code Online (Sandbox Code Playgroud) 我在这里阅读了类似的问题并在我的应用程序中编写了此方法
let formatter = NumberFormatter()
func convertEngNumToPersianNum(num: String)->String{
let number = NSNumber(value: Int(num)!)
let format = NumberFormatter()
format.locale = Locale(identifier: "fa_IR")
let faNumber = format.string(from: number)
return faNumber!
}
Run Code Online (Sandbox Code Playgroud)
我没有得到错误但我也没有得到结果!
我的号码代码是这样的:
let checkNumber = Home2ViewController().customtitle.count
personalCustom.text = ("\(checkNumber)")
Run Code Online (Sandbox Code Playgroud)
我在另一个有效的视图控制器中使用了另一个数字但我想以波斯语或阿拉伯数字格式而不是英语格式显示此数字
我读了 如何垂直居中 UICollectionView 内容 但是当我在这里使用代码时
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
let navBarHeight = self.navigationController?.navigationBar.frame.height
let collectionViewHeight = (self.collectionView?.frame.height)! - navBarHeight!
let itemsHeight = self.collectionView?.contentSize.height
let topInset = ( collectionViewHeight - itemsHeight! ) / 4
return UIEdgeInsetsMake(topInset ,0, 0 , 0)
}
Run Code Online (Sandbox Code Playgroud)
但是当滚动集合视图时,这将显示不正确的形式,所以这是我的代码,因为我的集合视图单元格是方形的并且等于屏幕宽度
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
showImagesCV.contentInset = UIEdgeInsets(top: spacing, left: spacing, bottom: spacing, right: spacing)
if let flowLayout = showImagesCV.collectionViewLayout as? UICollectionViewFlowLayout{
cellWidth = UIScreen.main.bounds.width
cellHeight = cellWidth //yourCellHeight = …Run Code Online (Sandbox Code Playgroud) ios uicollectionview uicollectionviewcell uicollectionviewlayout swift4
嗨,我正在使用post and get响应方法,它工作良好,但是有两个问题:1-当响应为get时,我无法使用警报; 2-在另一个变化的响应中,我无法获得api_token和Id
这是我用于发布的代码**我使用的是本地代码,但是您可以更改网址并对此进行测试**
var request = URLRequest(url: URL(string: "http://172.16.15.137:8888/TheoryTipo/public/api/register")!)
request.httpMethod = "POST"
let postString = "name=\(usernameforsignup.text!)&email=\(emailforsignup.text!)&password=\(passwordforsignup.text!)&tel=\(phonenumberforsignup.text!)"
print(postString)
request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
// check for fundamental networking error
print("error=\(error)")
let alertController = UIAlertController(title: "Error", message: "can't Connect to the server", preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction(title: "retry", style: UIAlertActionStyle.default)
{
(result : UIAlertAction) -> Void in
}
alertController.addAction(okAction)
self.present(alertController, …Run Code Online (Sandbox Code Playgroud) 我正在使用swift 3 - 我知道如何使用自定义Cell在集合视图中显示一些图像 - 问题是我无法在集合视图控制器中使用自定义单元
这里是集合视图控制器代码私有让reuseIdentifier ="uploadCell"
class uploadedFiles:UICollectionViewController {
var images = ["1.jpg" , "2.jpg" , "3.jpg" , "4.jpg" ]
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath)
//myCollectionView.sizeToFit()
//cell.sizeToFit()
cell.cellImages.image = UIImage(named: images[indexPath.row])
return cell
}
Run Code Online (Sandbox Code Playgroud)
这是收集视图单元代码
import UIKit
class UICollectionViewCell: UICollectionViewCell {
@IBOutlet weak var cellImages: UIImageView!
}
Run Code Online (Sandbox Code Playgroud)
记得我用"uploadCell"作为标识符
我在Swift 3中的文件管理器中有一些文件.我想上传它们,但是当我将它们转换为base 64时,它们的大小将是巨大的!所以我想在将数据转换为base 64之前压缩数据.
这是我的转换代码:
for i in 0...(rows?.count)! - 1 {
let filePath = filesurl[fileManagerViewController.selectedFileIndex[i]]
do {
let fileData = try Data.init(contentsOf: filePath)
let fileStream:String = fileData.base64EncodedString(options: NSData.Base64EncodingOptions.init(rawValue: 0))
fileManagerViewController.upupload.append(fileStream)
} catch {
print(error.localizedDescription)
}
}
Run Code Online (Sandbox Code Playgroud)
我用了
let compressedData = fileData(UF_COMPRESSED)
Run Code Online (Sandbox Code Playgroud)
但这对我不起作用,所以请在将文件转换为base 64进行上传之前帮助我压缩文件.
我已经阅读了类似这样的问题,但这些代码对我没有用,所以请帮助:我有一个表格视图,每个单元格中有一些按钮 - 这个表视图是用户的因素,我添加了按钮到该tableview - 当用户有付费的钱按钮隐藏在那个单元格中的那个因素中,另一个单元格中隐藏另一个因素当用户没有支付付款时没有隐藏 - 这就是我想要检测哪些单元格按钮按下了?!我知道在表视图中我们可以检测到哪个单元格已被按下但是这是不同的,因为用户只需按下该单元格中的按钮不按下所有单元格
由于我的代码太长,我只需将表格视图代码放在这里
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "factorCell", for: indexPath) as! FactorCell
cell.factorTitle.text = factorTitle[indexPath.row]
cell.factorCode.text = factorCodes[indexPath.row]
cell.factorDate.text = factorDate[indexPath.row]
cell.factorHour.text = factorHour[indexPath.row]
cell.factorPrice.text = factorPrice[indexPath.row]
cell.factorCondition.text = factorConditions[indexPath.row]
cell.factorBill.tag = indexPath.row
cell.factorBill.addTarget(self,action:#selector(factorViewController.Bill), for: UIControlEvents.touchUpInside)
cell.factorDetail.tag = indexPath.row
cell.factorDetail.addTarget(self,action:#selector(factorViewController.FactorDetail), for: .touchUpInside)
if factorConditions[indexPath.row] == "?????? ???" {
cell.factorBill.isHidden = true
} else {
cell.factorCondition.textColor = UIColor.red
cell.factorBill.isHidden = false
}
return cell
} …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序中解析JSON,并且一些JSON具有nil我处理的值.但是,该应用程序仍然显示JSON包含nil值的错误.我的代码:
struct Response : Decodable {
let articles: [Article]
}
struct Article: Decodable {
let title: String
let description : String
let url : String
let urlToImage : String
}
URLSession.shared.dataTask(with: url) { (data, response, error) in
guard let data = data else { return }
do {
let article = try JSONDecoder().decode(Response.self , from : data)
for i in 0...article.articles.count - 1 {
if type(of: article.articles[i].title) == NSNull.self {
beforeLoadNewsViewController.titleArray.append("")
} else {
beforeLoadNewsViewController.titleArray.append(article.articles[i].title)
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 Kingfisher 库,但我的问题是我不能将它用于存储在资产中的图像 - 所有 Kingfisher 方法都需要 url,那么我如何将它用于资产?
我想知道是否有任何方法可以打开或关闭iPhone wifi或以快速4的代码将设备切换到离线模式,或者我不知道苹果可能不允许该应用执行此类操作以在App Store中分发。这不重要,我只想知道是否有任何代码可以执行此操作(仅在Swift 4中)
ios ×10
swift3 ×7
swift4 ×3
swift ×2
assets ×1
base64 ×1
cell ×1
compression ×1
http-post ×1
image ×1
iphone ×1
json ×1
kingfisher ×1
nsdata ×1
nsformatter ×1
null ×1
offline-mode ×1
textfield ×1
uibutton ×1
uicolor ×1
uitabbaritem ×1
uitableview ×1
wifi ×1
xcode8.2 ×1