我真的尝试了所有我能做到的但是没有一个能用于定制UIView......我只是想要一个带圆角的白色空白视图和一个浅色阴影(没有光照效果).我可以一个接一个地做这些,但通常clipToBounds/ maskToBounds冲突发生.
我在Interface Builder中创建了一个自定义UICollectionViewCell,将它绑定到类上,然后当我想使用并将字符串设置为字符串上的标签时,tha label的值为nil.
override func viewDidLoad() {
super.viewDidLoad()
// Register cell classes
self.collectionView.registerClass(LeftMenuCollectionViewCell.self, forCellWithReuseIdentifier: "ls")
}
override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
var cell: LeftMenuCollectionViewCell
cell = collectionView.dequeueReusableCellWithReuseIdentifier("ls", forIndexPath: indexPath) as LeftMenuCollectionViewCell
println(cell.label) // <- this is nil, why??
cell.label.text = "asd"
return cell
}
Run Code Online (Sandbox Code Playgroud)
和子类细胞:
class LeftMenuCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var imageView: UIImageView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var activityIndicatorView: UIActivityIndicatorView!
}
Run Code Online (Sandbox Code Playgroud) 当我试图把UICollectionCell以UICollectionView在Interface Builder,我不能把它与原因不明.单元格将转到工具栏而不添加UICollectionView
我在用:
我已经和Swift和iOS合作了好几个月了.我熟悉许多方法,但我不够好,我可以不用看就写出来.我很欣赏Stack Overflow过去提供的快速答案,让我回到正轨,我已经生锈了(例如,AsyncTask Android示例).
iOS UITableView对我来说属于这一类.我已经完成了几次,但我忘记了细节.我在StackOverflow上找不到另一个问题,只是要求一个基本的例子,我正在寻找比许多在线教程更短的东西(虽然这个非常好).
我将在下面提供一个答案供我将来参考和你的.
我有一个以编程方式创建的UICollectionView.我希望集合视图以下列方式运行:
1. User touches cell
2. Cell background color changes
3. User releases touch
4. Cell background color changes
Run Code Online (Sandbox Code Playgroud)
这应该是一个快速的颜色更改,它发生在与执行tap操作相关的选择器之前,其中包含集合视图的viewcontroller从堆栈中弹出.
我一直在看这个问题:UICollectionView单元格改变背景,同时点击
其中有以下用于此目的的方法摘要:
// Methods for notification of selection/deselection and highlight/unhighlight events.
// The sequence of calls leading to selection from a user touch is:
//
// (when the touch begins)
// 1. -collectionView:shouldHighlightItemAtIndexPath:
// 2. -collectionView:didHighlightItemAtIndexPath:
//
// (when the touch lifts)
// 3. -collectionView:shouldSelectItemAtIndexPath: or - collectionView:shouldDeselectItemAtIndexPath:
// 4. -collectionView:didSelectItemAtIndexPath: or -collectionView:didDeselectItemAtIndexPath:
// 5. -collectionView:didUnhighlightItemAtIndexPath:
Run Code Online (Sandbox Code Playgroud)
我假设我只需要从"触摸开始时"和"触摸结束时"实现上述方法之一.但无论我做什么,似乎背景颜色会发生变化,然后仍然会发生变化.这是我尝试过的一些不起作用的例子:
- (void)collectionView:(UICollectionView …Run Code Online (Sandbox Code Playgroud) objective-c ios uicollectionview uicollectionviewcell uicollectionviewdelegate
在构建iPad应用程序时,如何在UICollectionViewCell周围绘制边框?
更多细节:我实现了一个扩展UICollectionViewCell的ProductCell类.现在,我想分配一些奇特的细节,例如边框,阴影等.但是,当试图在这里使用类似的东西时,Xcode告诉我接收器类型'CALayer'是一个前向声明.
在UITableView中,可以使用完全静态的tableView配置.您可以断开UITableView的数据源,并使用IB将每个单元格放在故事板(或xib)上.
我用UICollectionView尝试了同样的事情.断开UICollectionView的数据源.将每个单元格放在故事板上的UICollectionView上.我没有任何错误地构建它.但它没有奏效.根本没有显示细胞.
没有数据源的UICollectionView可能吗?
我从未使用过UICollectionViewControllers,我认为它们与UITableViewControllers 有些相似,但令我惊讶的是,我无法UICollectionViewCell像使用自定义UITableViewCells 那样将UI元素添加到自定义s中.
实际上,我可以在Interface Builder中添加标签,按钮等,但是当我运行应用程序时,单元格显示为空.
我已经注册了在细胞类viewDidLoad通过调用方法(void)registerClass:(Class)cellClass forCellWithReuseIdentifier:(NSString *)identifier,我已经检查了我回国的有效实例UICollectionViewCell的(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath方法.
我究竟做错了什么?
我创建了一个UIcollectionView和一个带有一些字符串的数组@ [@"Item One","Item Two",@"Item Three"];
在Tableview中我会这样做:
NSString *object = self.titlesArray[indexPath.row];
cell.textLabel.text = object;
Run Code Online (Sandbox Code Playgroud)
但我真的无法弄清楚如何为UIcollectionView中的Items执行此操作.
我在故事板中有一个UICollectionView,位于UICollectionViewController中.UICollectionViewController链接到我的自定义class MasterViewController: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate,它的委托和数据源在故事板中链接到这个类.
我在故事板中有一个原型UICollectionViewCell,标识符为"MyCell",来自我的自定义 class Cell: UICollectionViewCell
在该cellForItemAtIndexPath方法中,应用程序在该行崩溃:let cell:Cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCell", forIndexPath: indexPath) as Cell
我找不到原因.我没有实现该registerClass:forCellWithReuseIdentifier:方法,故事板的标识符恰好是"MyCell",我检查了很多次,并且委托和数据源链接到正确的类.
当应用程序崩溃时,控制台中没有打印任何内容,只是"(lldb)"
这是我的代码:
class MasterViewController: UICollectionViewController,UICollectionViewDataSource,UICollectionViewDelegate {
var objects = [ObjectsEntry]()
@IBOutlet var flowLayout: UICollectionViewFlowLayout!
override func awakeFromNib() {
super.awakeFromNib()
}
override func viewDidLoad() {
super.viewDidLoad()
flowLayout.itemSize = CGSizeMake(collectionView!.bounds.width - 52, 151)
}
// MARK: - Collection View
override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> …Run Code Online (Sandbox Code Playgroud) ios ×9
objective-c ×5
swift ×3
iphone ×2
cocoa-touch ×1
ios8 ×1
storyboard ×1
uitableview ×1
uiview ×1