小编Jon*_*lin的帖子

未调用UICollectionView insetForSectionAtIndex

我有一个具有以下声明和构造函数的类:

class GameView: UIView, UICollectionViewDelegate,  UICollectionViewDataSource, UICollectionViewDelegateFlowLayout
{
    var collectionView: UICollectionView?
    var flowLayout =  UICollectionViewFlowLayout()

    init (frame : CGRect, navigationController:UINavigationController, parentViewController: ScrambleViewController)
{
    super.init(frame : frame)
    cvFrame = CGRect(x: cvLeftBorder, y: cvY, width: Int(UIScreen.main.bounds.width) -  (2 * cvLeftBorder), height: cvHeight)
    collectionView = UICollectionView(frame: cvFrame!, collectionViewLayout: flowLayout);
    collectionView!.dataSource = self
    collectionView!.delegate = self;
    .....
}
Run Code Online (Sandbox Code Playgroud)

这是一种每轮都有不同数量的细胞的游戏.我想将细胞居中,所以我插入:

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets {

 // calculate the insets and return a UIEdgeInsets
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,永远不会调用该函数.否则,程序运行正常.或者是否有更好的方法让细胞在每一轮中心?

提前致谢.

uicollectionview uicollectionviewlayout swift

7
推荐指数
2
解决办法
3389
查看次数

iOS 上可用的字体

我正在尝试用 Swift 制作一个UILabel- 标签将显示简体中文字符。我正在尝试使用 Mac 附带的 Kaiti SC 字体,它在字体簿和 Mac 上的所有程序中都可用,但是当我使用以下代码列出字体时,它没有显示。

\n\n
    let fontFamilyNames = UIFont.familyNames()\n\n    for familyName in fontFamilyNames {\n\n        print("Font Family Name = [\\(familyName)]")\n        let names = UIFont.fontNamesForFamilyName(familyName)\n        print("Font Names = [\\(names)]")\n    }\n
Run Code Online (Sandbox Code Playgroud)\n\n

我的 UILabel 的代码如下:

\n\n
   let characterLabel:UILabel! = UILabel(frame: CGRectMake(600,140,300,300));\n\n   characterLabel.font = UIFont(name:"Kaiti SC" , size:250.0);\n\n   characterLabel.text = "\xe8\xaf\xb4";\n
Run Code Online (Sandbox Code Playgroud)\n\n

我本以为 Mac 上的所有字体都可以在我的 Swift 程序中使用。(当然,该代码可以与其他字体(例如“Baskerville”)一起使用,汉字在这些字体中看起来不太好。)有什么想法吗?

\n

xcode fonts ios swift

4
推荐指数
1
解决办法
7955
查看次数