小编pul*_*ulp的帖子

UICollectionView的动态单元格宽度取决于标签宽度

我有一个UICollectionView,它从可重用的单元格加载单元格,其中包含标签.数组为该标签提供内容.我可以使用sizeToFit轻松调整标签宽度,具体取决于内容宽度.但我不能让细胞贴合标签.

这是代码

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    arrayOfStats =  @[@"time:",@"2",@"items:",@"10",@"difficulty:",@"hard",@"category:",@"main"];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:     (NSInteger)section{
    return [arrayOfStats count];
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{

    return CGSizeMake(??????????);
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{

    return 1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    Cell *cell = (Cell *) [collectionView dequeueReusableCellWithReuseIdentifier:@"qw" forIndexPath:indexPath];
    cell.myLabel.text = [NSString stringWithFormat:@"%@",[arrayOfStats objectAtIndex:indexPath.item]];
    // make label width depend on text width
    [cell.myLabel sizeToFit];

    //get the width …
Run Code Online (Sandbox Code Playgroud)

objective-c ios uicollectionview uicollectionviewcell swift

80
推荐指数
7
解决办法
7万
查看次数

如何从锁定屏幕和控制中心隐藏 MPMediaItemPropertyPlaybackDuration 滑块?

我正在开发在线广播播放器,需要一些帮助。当我设置时,MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo我有标题、控件和播放持续时间滑块。我不需要这个滑块,因为我没有有关播放持续时间的信息,而且它不是一个很好看的控件。有人可以提示我如何隐藏播放持续时间滑块吗?还有一个问题:由于该应用程序是在线广播播放器,因此用户无法前进或后退播放,因此我想从锁定屏幕和控制中心隐藏此控件。顺便说一句,我正在使用 Swift。提前致谢!

controls ios avplayer swift

5
推荐指数
1
解决办法
2591
查看次数

CAEmitterCell颜色属性不起作用

我对CAEmitterCell颜色属性有一些奇怪的行为,或者我不太了解。

我有一个牢房

let cell = CAEmitterCell()
Run Code Online (Sandbox Code Playgroud)

具有简单的.png文件的内容,该文件被绘制为黑色

cell.contents = UIImage(named: "particle")?.cgImage
Run Code Online (Sandbox Code Playgroud)

我尝试将其更改为绿色

cell.color = UIColor.green.cgColor
Run Code Online (Sandbox Code Playgroud)

但是它仍然是黑色的。我试图将媒体资源中此图像的“渲染为”属性更改为“模板图像”,但没有效果。

谁能帮助我了解我在做什么错?

colors ios caemitterlayer caemittercell swift

5
推荐指数
2
解决办法
454
查看次数

什么"在Swift语言中意味着什么?

请有人向我解释一些奇怪的Swift语法,我试图谷歌它并检查Apple的文档,但没有找到任何使用它的例子.所以这里是我试图遵循的教程中的一些代码. let FSBoundaryCategory: UInt32 = 1 << 0

我没有得到什么意思<<.

这绝对不是两倍左右:)请解释一下,我对此非常好奇:)

syntax ios swift

0
推荐指数
1
解决办法
1675
查看次数