我想要实现的是3x3表UICollectionView.但它在运行应用程序时不会显示任何单元格.它确实显示了背景颜色CollectionView(我设置为蓝色)有人可以帮助我吗?
我所做的就是创建一个storyboard并简单地将其CollectionViewController拖到它上面.这个控制器还带了一个嵌套CollectionView它.然后我只是使用设置使其背景为蓝色并添加一个单元格,我将背景设为紫色(两者仅用于测试).最后把UILabel它拖到了它上面.现在运行时它只显示蓝色背景但没有单元格,即使它们在编辑器中清晰可见.然后我尝试创建一个自定义UICollectionViewController,将类分配给CollectionViewController而不是标准类,并对单元格执行相同的操作(分配自定义UICollectionViewCell).在自定义中UICollectionViewController我实现了以下方法:
-(NSIntegear)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier = @"Cell";
AboutYourGoalsMultiSelectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];
[[cell goal]setText:@"T"];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
我将单元格的标识符设置为"Cell",并在CollectionView和自定义UICollectionViewController之间建立了dataSource和委托的出口连接.一切都很好.那我错过了什么?通过简单地使用编辑器进行所有这些调整之前,它不应该显示出某种方式吗?

我已使用本地通知将我的应用的徽章编号设置为1.然后我卸载了应用程序.当我重新安装它时,徽章仍在那里.这是一个iOS错误还是有一种方法可以在卸载时清除徽章?
谢谢.
我想添加一个覆盖整个屏幕的暗视图层.
为了做到这一点,我将UIView对象添加到window属性,UIViewController如下所示.我记得我能够window在ios6中添加这样的视图.但是,它在ios7中不起作用.
我怎么能让它工作?
提前致谢!!
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
overlayView.backgroundColor = [UIColor blackColor];
overlayView.alpha = 0.8;
[self.view.window addSubview:overlayView];
}
Run Code Online (Sandbox Code Playgroud) 我希望每次应用变为活动时都会显示启动画面.我创建了一个showSplash我调用的函数applicationDidBecomeActive:
-(void)showSplash
{
UIImageView *splashScreen = [[UIImageView alloc] initWithImage:[UIImage imageNamed: @"Default.png"]];
[self.window.rootViewController.view addSubview: splashScreen];
[self.window makeKeyAndVisible];
NSLog(@"begin splash");
[UIView animateWithDuration: 4.2
delay: 0.5
options: UIViewAnimationOptionCurveEaseOut
animations: ^{
splashScreen.alpha = 0.0;
}
completion: ^ (BOOL finished) {
[splashScreen removeFromSuperview];
NSLog(@"end splash");
}
];
}
Run Code Online (Sandbox Code Playgroud)
这就是我调用这个函数的方式:
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self showSplash];
}
Run Code Online (Sandbox Code Playgroud)
但是没有闪屏.请指正.
我想将文本UILabel转换为圆形(而不是矩形).我做了一些实验用NSLayoutManager,NSTextContainer和NSTextStorage,但它似乎并没有工作.以下示例应该将文本流入40x40的较小矩形(标签为120x120),但似乎没有任何影响.
UIFont *font = [UIFont fontWithName:@"HelveticaNeue" size:12];
NSTextStorage *ts = [[NSTextStorage alloc] initWithString:multiline.title attributes:@{NSFontAttributeName:font}];
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
NSTextContainer *tc = [[NSTextContainer alloc] initWithSize:CGSizeMake(40, 40)];
[lm addTextContainer:tc];
[ts addLayoutManager:lm];
self.label.attributedText = ts;
Run Code Online (Sandbox Code Playgroud)
Ides的?
我认为iOS 7 MKMapSnapshotter是一种拍摄快照的简单方法MKMapView,其好处是可以在不将地图加载到视图中的情况下完成.即使添加引脚和覆盖图似乎更多的工作(因为需要核心图形).WWDC视频提供了一个非常好的例子来创建一个MKMapSnapshotter添加MKAnnotationView.
然而,对于没有很多核心图形经验的人来说,如何创建一个MKMapSnapshotter来自的人并不是很明显MKPolylineRenderer.
我试过这样做,但路径不准确.它准确地绘制了大约10%的线,但随后直接绘制了剩下的路径.
这是我的代码:
MKMapSnapshotter *snapshotter = [[MKMapSnapshotter alloc] initWithOptions:snapshotOptions];
[snapshotter startWithQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
completionHandler:^(MKMapSnapshot *snapshot, NSError *error)
{
if (error == nil)
{
UIImage *mapSnapshot = [snapshot image];
UIGraphicsBeginImageContextWithOptions(mapSnapshot.size,
YES,
mapSnapshot.scale);
[mapSnapshot drawAtPoint:CGPointMake(0.0f, 0.0f)];
CGContextRef context = UIGraphicsGetCurrentContext();
//Draw the points from the MKPolylineRenderer in core graphics for mapsnapshotter...
MKPolylineRenderer *overlay = (MKPolylineRenderer *)[self.mapView rendererForOverlay:[_mapView.overlays lastObject]];
if (overlay.path)
{
CGFloat zoomScale = 3.0;
[overlay applyStrokePropertiesToContext:context
atZoomScale:zoomScale];
CGContextAddPath(context, …Run Code Online (Sandbox Code Playgroud) 我继承的项目目前使用Parse作为后端.我正在尝试迁移数据的获取/发布方式,从Parse iOS SDK迁移到使用Parse REST API(使用AFNetworking).
我能够将PFQuery类似下面的简单转换为它的REST等价物:
PFQuery
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.'999Z'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *createdAt = [dateFormatter stringFromDate:createdAtDate];
PFQuery *query = [PFQuery queryWithClassName:@"Photo"];
[query whereKey:@"createdAt" lessThan:createdAt];
[query orderByDescending:@"createdAt"];
[query setLimit:10];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
//Etc...
}
}];
Run Code Online (Sandbox Code Playgroud)
REST API请求:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.'999Z'"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
NSString *createdAt = [dateFormatter stringFromDate:createdAtDate];
NSString *dateQueryString = [NSString stringWithFormat:@"{\"createdAt\":{\"$lte\":{\"__type\":\"Date\",\"iso\":\"%@\"}}}", createdAt];
NSDictionary* parameters = @{@"order": …Run Code Online (Sandbox Code Playgroud) 我可以使用以下代码成功地将轻击手势添加到UITextView的一部分:
UITextPosition *pos = textView.endOfDocument;// textView ~ UITextView
for (int i=0;i<words*2-1;i++){// *2 since UITextGranularityWord considers a whitespace to be a word
UITextPosition *pos2 = [textView.tokenizer positionFromPosition:pos toBoundary:UITextGranularityWord inDirection:UITextLayoutDirectionLeft];
UITextRange *range = [textView textRangeFromPosition:pos toPosition:pos2];
CGRect resultFrame = [textView firstRectForRange:(UITextRange *)range ];
UIView* tapViewOnText = [[UIView alloc] initWithFrame:resultFrame];
[tapViewOnText addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(targetRoutine)]];
tapViewOnText.tag = 125;
[textView addSubview:tapViewOnText];
pos=pos2;
}
Run Code Online (Sandbox Code Playgroud)
我希望在a中模仿相同的行为UILabel.问题是,UITextInputTokenizer(使用来标记个人的话)的宣布UITextInput.h,只UITextView与UITextField符合UITextInput.h; UILabel才不是.这有解决方法吗?
我用来SDWebImage异步下载图像到我的UIImageViews.收到的大多数图像都是可接受的尺寸,可以轻松下载,并设置为UIImageViews.
但有时候,URL上的源图像分辨率非常高(相对于我的大小imageView- 60x60).在这种情况下,永远不会设置图像.有时我的应用程序崩溃,有时,没有任何事情发生(图像停留nil),并且在极少数情况下我收到了类似的错误:( Unable to allocate 400000 bytes of memory我不完全确定确切的错误日志,我道歉).
例如,这从Pinterest的站点本身的Pinterest的图标的图像是巨大的(10000×10000).我imageView永远无法绘制这张图片.目前,我已经硬编码用这个替换图像,但我知道这是不好的做法.此外,这只是一种情况,可能会有无限多的图像,这可能会影响用户体验.
我该如何处理这类案件?
嗨下面是我需要实现的视图UILabel.我听说过NSAttributedString但不确定如何使用它进行动态文本加载.

整个文本字体是Roboto-Light.但是,我必须从前两位医生的API响应中替换文本'Andrew Murphy博士,John Smith',并从API获得"23位医生"的计数,以便相应地调整此标签.您可以看到的文本颜色取决于文本是常量还是动态.我不知道如何实现它.因此,一些代码片段真的很受欢迎.
谢谢!
ios ×10
objective-c ×5
ios7 ×3
iphone ×3
uilabel ×3
ipad ×1
mkmapview ×1
mkpolyline ×1
rest ×1
sdwebimage ×1
textkit ×1
uiimageview ×1
uitextinput ×1