我之前使用minimumFontSize过,但该功能现已弃用,我不太明白它是如何minimumScaleFactor工作的.
我希望最大字体大小为10,最小字体大小为7.
如何使用比例因子将尺寸缩小到字体大小7?
UILabel 创建:
UILabel *label = [[UILabel alloc] init];
[label setTranslatesAutoresizingMaskIntoConstraints:NO];
label.text = [labelName uppercaseString];
label.textAlignment = NSTextAlignmentCenter;
label.textColor = [UIColor whiteColor];
label.font = [UIFont fontWithName:HELVETICA_FONT_STYLE_BOLD size:9.5];
label.backgroundColor = [UIColor clearColor];
label.minimumScaleFactor = .1f;
[label addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[label(WIDTH)]"
options:0
metrics:@{@"WIDTH" : [NSNumber numberWithFloat:buttonSize.width]}
views:NSDictionaryOfVariableBindings(label)]];
[contentView addSubview:label];
Run Code Online (Sandbox Code Playgroud) 选择单元格后,我想处理更改单元格外观.我想委托方法collectionView:didSelectItemAtIndexPath:&collectionView:didDeselectItemAtIndexPath:是我应该编辑细胞.
-(void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
DatasetCell *datasetCell =
(DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
[datasetCell replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]];
datasetCell.backgroundColor = [UIColor skyBlueColor];
}
Run Code Online (Sandbox Code Playgroud)
-(void)collectionView:(UICollectionView *)collectionView
didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
DatasetCell *datasetCell =
(DatasetCell *)[collectionView cellForItemAtIndexPath:indexPath];
[datasetCell replaceHeaderGradientWith:[UIColor grayGradient]];
datasetCell.backgroundColor = [UIColor myDarkGrayColor];
}
Run Code Online (Sandbox Code Playgroud)
这种方法很好,除非重用单元格.如果我在索引(0,0)处选择单元格,它会更改外观,但是当我向下滚动时,会有另一个单元格处于选定状态.
我相信我应该使用这种UICollectionViewCell方法-(void)prepareForReuse来准备细胞以便重复使用(即,将细胞外观设置为非选择状态),但它给我带来了困难.
-(void)prepareForReuse {
if ( self.selected ) {
[self replaceHeaderGradientWith:[UIColor skyBlueHeaderGradient]];
self.backgroundColor = [UIColor skyBlueColor];
} else {
[self replaceHeaderGradientWith:[UIColor grayGradient]];
self.backgroundColor = [UIColor myDarkGrayColor];
}
}
Run Code Online (Sandbox Code Playgroud)
当我向后滚动到顶部时,索引(0,0)处的单元格处于取消选择状态.
当我刚刚使用cell.backgroundView属性时,为了防止这种情况发生在:
-(void)prepareForReuse { …Run Code Online (Sandbox Code Playgroud) 我发现了一个关于如何制作粘性标题的博客,它的效果非常好.唯一的问题是我不认为它考虑了sectionInserts.
这是它的目的:

我有我的插页:
collectionViewFlowLayout.sectionInset = UIEdgeInsetsMake(16, 16, 16, 16);
Run Code Online (Sandbox Code Playgroud)
使用粘性标题,它向下移动16个像素:

我尝试使用原始代码进行调试,我认为问题出在最后一部分:
layoutAttributes.frame = (CGRect){
.origin = CGPointMake(origin.x, origin.y),
.size = layoutAttributes.frame.size
Run Code Online (Sandbox Code Playgroud)
如果我将其更改为origin.y - 16,则标题将从正确的位置开始,但是当向上推时,头部的16个像素会离开屏幕:

我不知道如何让它考虑到sectionInsects.有人可以帮忙吗?
以下是博客中的完整代码:
- (NSArray *) layoutAttributesForElementsInRect:(CGRect)rect {
NSMutableArray *answer = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
UICollectionView * const cv = self.collectionView;
CGPoint const contentOffset = cv.contentOffset;
NSMutableIndexSet *missingSections = [NSMutableIndexSet indexSet];
for (UICollectionViewLayoutAttributes *layoutAttributes in answer) {
if (layoutAttributes.representedElementCategory == UICollectionElementCategoryCell) {
[missingSections addIndex:layoutAttributes.indexPath.section];
}
}
for (UICollectionViewLayoutAttributes *layoutAttributes in answer) {
if ([layoutAttributes.representedElementKind isEqualToString:UICollectionElementKindSectionHeader]) …Run Code Online (Sandbox Code Playgroud) 所以我注册了我的手机:
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// setting up the cell
}
Run Code Online (Sandbox Code Playgroud)
问题是我无法设置cell.detailTextLabel.text属性.细胞永远不会nil.
在一个方法中,我想在n秒后调用一个方法:
self.toolBarState = [NSNumber numberWithInt:1];
[self changeButtonNames];
[self drawMap];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:2];
Run Code Online (Sandbox Code Playgroud)
我想在drawMap完成后2秒显示操作表.当我使用这个performSelector时,它从不拨打电话.
如果我只是把[self showActionSheet];,它的工作正常.有没有理由说performSelector没有打电话?
编辑:在我的代码的另一部分,我进行相同的调用,它的工作原理:
HUD = [[MBProgressHUD alloc] initWithView:self.view];
[self.view addSubview:HUD];
HUD.delegate = (id) self;
[HUD showWhileExecuting:@selector(drawMap) onTarget:self withObject:nil animated:YES];
[self performSelector:@selector(showActionSheet) withObject:nil afterDelay:6];
Run Code Online (Sandbox Code Playgroud)
这里,showActionSheet在drawMap完成后6秒被调用.我猜我的线程还有什么东西我还不明白......
EDIT2:
-(void)showActionSheet
{
InspectAppDelegate *dataCenter = (InspectAppDelegate *) [[UIApplication sharedApplication] delegate];
if (dataCenter.fieldIDToPass == nil)
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Selected Boundary Options" delegate:(id) self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Analyze a Field",@"Retrieve Saved Analysi", @"Geotag Photos", @"Refresh the map",nil];
actionSheet.tag = 0;
[actionSheet …Run Code Online (Sandbox Code Playgroud) 我希望能够判断tap是否在MKPolygon中.
我有一个MKPolygon:
CLLocationCoordinate2D points[4];
points[0] = CLLocationCoordinate2DMake(41.000512, -109.050116);
points[1] = CLLocationCoordinate2DMake(41.002371, -102.052066);
points[2] = CLLocationCoordinate2DMake(36.993076, -102.041981);
points[3] = CLLocationCoordinate2DMake(36.99892, -109.045267);
MKPolygon* poly = [MKPolygon polygonWithCoordinates:points count:4];
[self.mapView addOverlay:poly];
//create UIGestureRecognizer to detect a tap
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(foundTap:)];
tapRecognizer.numberOfTapsRequired = 1;
tapRecognizer.numberOfTouchesRequired = 1;
[self.mapView addGestureRecognizer:tapRecognizer];
Run Code Online (Sandbox Code Playgroud)
它只是科罗拉多州的基本轮廓.
我得到了lat/long转换设置:
-(IBAction)foundTap:(UITapGestureRecognizer *)recognizer
{
CGPoint point = [recognizer locationInView:self.mapView];
CLLocationCoordinate2D tapPoint = [self.mapView convertPoint:point toCoordinateFromView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
但如果我的分接点在MKPolygon内,我不确定如何技术.似乎没有办法做这个检查,所以我猜我需要将MKPolygon转换为CGRect并使用CGRectContainsPoint.
MKPolygon有一个.points属性,但我似乎无法让它们退出.
有什么建议?
编辑:
以下两种解决方案均适用于iOS 6或更低版本,但在iOS 7中有效.在iOS 7中,该polygon.path属性始终返回NULL.安娜女士非常友好地提供了另一个SO问题的解决方案.它涉及从多边形点创建自己的路径以进入 …
试图在我UICollectionView的标题中添加一个补充视图.我有问题让它工作.
我使用一个自定义UICollectionViewFlowLayout来返回一个contentSize总是至少比帧大1个像素(我使用的UIFreshControl只有UICollectionView滚动,并且设置collectionView.contentSize直接无效)并invalidateLayout打开sectionInsert和itemSize更改:
-(void)setSectionInset:(UIEdgeInsets)sectionInset {
if (UIEdgeInsetsEqualToEdgeInsets(super.sectionInset, sectionInset)) {
return;
}
super.sectionInset = sectionInset;
[self invalidateLayout];
}
-(void) setItemSize:(CGSize)itemSize {
if (CGSizeEqualToSize(super.itemSize, itemSize)) {
return;
}
super.itemSize = itemSize;
[self invalidateLayout];
}
- (CGSize)collectionViewContentSize
{
CGFloat height = [super collectionViewContentSize].height;
// Always returns a contentSize larger then frame so it can scroll and UIRefreshControl will work
if (height < self.collectionView.bounds.size.height) {
height = …Run Code Online (Sandbox Code Playgroud) 我试图将tableview的偏移量设置为动画,然后在完成块中将其向上移动.但是我的代码在完成块中没有做任何事情:
-(void)viewDidAppear:(BOOL)animated {
if (TRUE) {
NSLog(@"animating table view");
[UIView animateWithDuration:.25
animations:^{
self.tableView.contentOffset = CGPointMake(self.tableView.contentOffset.x, self.tableView.contentOffset.y - 60);
}
completion:^(BOOL finished){
NSLog(@"completion block");
}];
}
}
Run Code Online (Sandbox Code Playgroud)
"完成块"永远不会输出......任何想法?
编辑:
好的,所以它与我的UIREfreshControl有关:
- (void)viewDidLoad
{
[super viewDidLoad];
if (TRUE) {
UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
refresh.attributedTitle = [[NSAttributedString alloc] initWithString:@"Pull to Refresh"];
[refresh addTarget:self action:@selector(refreshTableView:) forControlEvents:UIControlEventValueChanged];
[self setRefreshControl:refresh];
}
}
Run Code Online (Sandbox Code Playgroud)
添加刷新控件时,它不会触发完成块.如果我不添加控件,它按预期工作.
编辑2:
K,所以如果我滚动表视图,则会触发完成块:
2013-02-15 13:37:06.266 [1922:14003] animating table view
2013-02-15 13:37:14.782 [1922:14003] completion block
Run Code Online (Sandbox Code Playgroud)
写入的代码应该在"动画表视图"之后立即记录"完成块",但是当我自己滚动表视图时它有8秒的延迟原因.
"拉动刷新"如何看起来像:

我创建了一个名为"MyObject"的核心数据实体.然后我重命名了实体"ThatObject".但每次我创建一个NSManagedObject子类时,它仍然会将.h/.m文件创建为MyObject.
我接受"MyObject"文件并将它们重命名为"ThatObject",一切正常,但每次改变实体属性时都必须这样做很烦人.
知道如何解决这个问题吗?
有一个应用程序,可以拍照,然后上传到服务器.将它编码为base 64并将其通过XMLRPC传递给我的php服务器.
我想获取从UIImagePickerController委托返回的NSDictionary信息
-(void) imagePickerController:(UIImagePickerController *)imagePicker didFinishPickingMediaWithInfo:(NSDictionary *)info
Run Code Online (Sandbox Code Playgroud)
并将其转换为NSData,以便我可以对其进行编码.
那么,我如何将NSDictionary转换为NSData?
iphone objective-c nsdictionary uiimagepickercontroller nsdata
objective-c ×10
ios ×9
iphone ×2
core-data ×1
mapkit ×1
mkmapview ×1
nsdata ×1
nsdictionary ×1
uilabel ×1
uitableview ×1