gpt4 book ai didi

ios - CollectionView 窗口保持黑色

转载 作者:可可西里 更新时间:2023-11-01 05:45:42 26 4
gpt4 key购买 nike

我正在编写 iOS 应用程序。我有 CollectionView 窗口,在其中通过拖放添加了一个 customCell。当我运行应用程序时,CollectionView 窗口的一部分是黑色的。集合可重用 View 标识符设置为“ItemCell”。自定义 View 单元设置为“CustomViewCell”类。 CollectionView 的数据源和委托(delegate)已设置为 FirstViewController。那是代码:

FirstViewcontroller:
#import <UIKit/UIKit.h>
#import "CustomViewCell.h"

@interface FirstViewController : UIViewController<UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txtField;

- (IBAction)slideRed:(id)sender;

- (IBAction)slideGreen:(id)sender;
- (IBAction)slideBlue:(id)sender;
- (IBAction)btnAdd:(id)sender;

@end

.m文件:

#import "FirstViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.


}
-(void)viewDidAppear:(BOOL)animated
{

}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 10;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 5;
}

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

CustomViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ItemCell" forIndexPath:indexPath];

if (cell == nil) {
cell = [[CustomViewCell alloc]init];
}


cell.label.text = @"KitKat";
//cell.lblMain.textColor = [UIColor whiteColor];
// cell.backgroundColor = [UIColor blackColor];

return cell;
}


- (IBAction)slideRed:(id)sender {
}

- (IBAction)slideGreen:(id)sender {
}

- (IBAction)slideBlue:(id)sender {
}

- (IBAction)btnAdd:(id)sender {
}
@end

自定义 View 单元格:

#import "CustomViewCell.h"

@implementation CustomViewCell
@synthesize label;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}



@end

如何强制 collectionView 窗口显示带有标签的 customCell。然而它只是一个黑色的窗口。最好的问候

最佳答案

无法使用默认透明度。但是解决方法解决了这个问题。1. 选择 Collection View 。2. 单击“背景”属性添加颜色。3. 选择一种颜色(在我的例子中是“白色”)4.将颜色“不透明度”设置为“0%”vola.. 你会得到一个透明的背景。

关于ios - CollectionView 窗口保持黑色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14662727/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com