我有这个问题。我需要像这个截图一样旋转工作表。
所以我用
旋转了UIView(SpreadsheetView
类中的子类)
spreadsheetView.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
并将其设为@IBDesignable
,这也是我在故事板中轮换视图的原因。
但是当应用程序启动时,我得到了这个结果:
如您所见,数据被裁剪,并且从未旋转的视图的蓝色边框开始裁剪(参见第一张图像,突出显示的矩形)。 如何以我需要的方向从视图的开头到结尾拟合数据?
我正在使用的库是SpreadsheetView,这是我的班级:
import UIKit
import SpreadsheetView
class TableChartViewController: UIViewController, SpreadsheetViewDataSource {
var headerString = ["Luogo", "Attività", "Umore", "Tot.", "Alta", "Media", "Bassa"]
var data = [[String]]()
@IBOutlet weak var spreadSheetView: SpreadsheetView!
override func viewDidLoad() {
super.viewDidLoad()
spreadSheetView.dataSource = self
spreadsheetView.transform = CGAffineTransform(rotationAngle: CGFloat.pi/2)
spreadSheetView.register(HeaderCell.self, forCellWithReuseIdentifier: String(describing: HeaderCell.self))
spreadSheetView.register(TextCell.self, forCellWithReuseIdentifier: String(describing: TextCell.self))
}
//sorting funcs
enum Sorting {
case ascending
case descending
var symbol: String {
switch self {
case .ascending:
return "\u{25B2}" //unicode for black up-pointing triangle
case .descending:
return "\u{25BC}" //unicode for black down-pointing triangle
}
}
}
var sortedColumn = (column: 0, sorting: Sorting.ascending)
//spreadSheetView funcs
func numberOfColumns(in spreadsheetView: SpreadsheetView) -> Int {
return headerString.count
}
func numberOfRows(in spreadsheetView: SpreadsheetView) -> Int {
return 5
}
func spreadsheetView(_ spreadsheetView: SpreadsheetView, widthForColumn column: Int) -> CGFloat {
return 80
}
func spreadsheetView(_ spreadsheetView: SpreadsheetView, heightForRow row: Int) -> CGFloat {
return 40
}
func spreadsheetView(_ spreadsheetView: SpreadsheetView, cellForItemAt indexPath: IndexPath) -> Cell? {
if case 0 = indexPath.row {
let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: HeaderCell.self), for: indexPath) as! HeaderCell
cell.label.text = headerString[indexPath.column]
if case indexPath.column = sortedColumn.column {
cell.sortArrow.text = sortedColumn.sorting.symbol
} else {
cell.sortArrow.text = ""
}
cell.setNeedsLayout()
return cell
} else {
let cell = spreadsheetView.dequeueReusableCell(withReuseIdentifier: String(describing: TextCell.self), for: indexPath) as! TextCell
cell.label.text = "Prova"
return cell
}
}
}