众所周知,UITabBarController中所选(或活动)项的色调颜色可以很容易地改变,这是一个例子:
myBarController.tabBar.tintColor = [UIColor redColor];
Run Code Online (Sandbox Code Playgroud)
在这种情况下,tabBar中的任何标签栏项目一旦激活就会有红色.同样,这适用于此标签栏中的所有项目.
如何在同一个栏中的其他标签栏项目之间显示活动色调颜色?例如,一个项目在选中时可能具有红色,而另一个项目可能具有蓝色色调.
我知道这可以通过重绘和子类化整个标签栏来解决.然而,这是我需要的唯一改变,这样做似乎有点过头了.我不是试图改变样式或如何以任何方式呈现项目,只是为了使不同项目之间的风格不同.
我没有看到任何与iOS 7和8中的更新相关的问题的答案.
我已经开始学习IOS,我想知道viewdidload:在视图出现在屏幕上之前调用该方法吗?苹果开发人员指南说这个方法在视图加载到内存后被调用但我不明白什么"加载到内存中"意味着,是否意味着视图没有出现在屏幕上?
我使用UITableViewControllerdetailView来显示一个实体细节.我在我的viewDidLoad方法中填充了PFQuery的一行数据.我有一个单元格,我正在使用标签,我想根据大小更改NSString大小.我检查了很多答案,但都与indexPath动态相关,我有静态单元格.My label显示完整的字符串,但我的单元格已修复.如何更改单元格的高度?请帮我纠正这个问题.
这是我的代码:
- (void)viewDidLoad
{
[super viewDidLoad];
PFQuery *query = [PFQuery queryWithClassName:@"Entities"];
[query whereKey:@"name" equalTo:entityName];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
PFFile *thumbnail = [objects[0] objectForKey:@"image"];
detailsImageView.image = [UIImage imageNamed:@"loader.gif"];
detailsImageView.file = thumbnail;
[detailsImageView loadInBackground];
detailLabel.numberOfLines = 0; // this label need dynamic height and its cell
detailLabel.text = [objects[0] objectForKey:@"descriptionLarge"];
[detailLabel sizeToFit];
} else {
NSString *errorString = [[error userInfo] objectForKey:@"error"];
NSLog(@"Error: %@", errorString);
} …Run Code Online (Sandbox Code Playgroud) 现在我正在学习汽车布局,我遇到了一个我无法解决的问题.
我有一个在4英寸设备中正确加载的视图(左视图),我正在尝试将其调整为3.5英寸设备,使其与图像上的右视图完全相同:

唯一的区别是绿色,橙色,黑色和粉红色视图应缩小一点,以保持上述两个视图的相同大小.
我的问题是我无法找到使用约束的方法.
这就是我已经拥有的约束所发生的事情:

我已经尝试将底部空间固定为黑色和粉红色视图的超视图,以便视图缩小以适应屏幕,但是这不起作用并且在Xcode上给了我很多警告.
我试图显示选定类型类型附近的地方 - 酒吧,咖啡厅,ATM等
我在开发者控制台上创建了项目.启用API(google places api,google map sdk,direction api)
我创建了iOS api密钥,但Api密钥无效.我收到此错误消息
此IP,站点或移动应用程序无权使用此API密钥.从IP地址114.143.244.10收到的请求,空引用
当我尝试浏览器api密钥时出现此错误
此API项目无权使用此API.请确保在API控制台中激活此API:了解详情:https://code.google.com/apis/console
我正在使用这个网址
NSString *url = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/search/json?location=%f,%f&radius=%@&types=%@&sensor=true&key=%@",
currentCentre.latitude,
currentCentre.longitude,
[NSString stringWithFormat:@"%i", currenDist],
googleType,
kGOOGLE_API_KEY
];
Run Code Online (Sandbox Code Playgroud)
我没有得到什么问题.
我正在尝试将日期选择器添加到警报视图.我可以根据按钮点击将动画添加到屏幕上,我看到一个黑盒但没有日期选择器.
这是我到目前为止所拥有的......
- (IBAction)showDatePicker {
CGRect frame = CGRectMake(200, self.view.frame.size.height, self.view.frame.size.width, 0); //CGRectMake(225, 145, 260, 125);
UIPickerView *datePicker = [[UIPickerView alloc] initWithFrame:frame];
UIAlertView *showDateAlert = [[UIAlertView alloc]
initWithTitle:@"Enter the Code Date"
message:@"Sample message"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Update", nil];
[self.view addSubview:datePicker];
[UIView beginAnimations:@"slideIn" context:nil];
[datePicker setCenter:CGPointMake(datePicker.frame.origin.x, self.view.frame.size.height - datePicker.frame.size.height/2)];
[UIView commitAnimations];
}
Run Code Online (Sandbox Code Playgroud)
我发现了一个似乎正在工作的示例但我没有在警报框中看到任何对话框或按钮,只有日期选择器本身.我在这里错过了什么吗?
- (IBAction)showDatePicker {
CGRect frame = CGRectMake(225, self.view.frame.size.height, self.view.frame.size.width, 125);
UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:frame];
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker setDate:[NSDate date]];
UIAlertView *alert; …Run Code Online (Sandbox Code Playgroud) 我在IOS中绘制应用程序时遇到了一些麻烦.我在一些教程的帮助下创建了自由手绘图.但我发现擦除图纸有些困难.在我的应用程序中,我有橡皮擦按钮作为背景图像.单击橡皮擦按钮后,当我在绘图上滑动时,无论我在哪里滑动,它都会擦除绘图.任何人都可以帮我这样做.提前致谢.
以下是我的代码:
@implementation LinearInterpView
{
UIBezierPath *path;
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
-(id)initWithCoder:(NSCoder *)aDecoder {
if(self = [super initWithCoder:aDecoder]) {
[self setMultipleTouchEnabled:YES];
[self setBackgroundColor:[UIColor whiteColor]];
path=[UIBezierPath bezierPath];
[path setLineWidth:2.0];
}
return self;
}
-(void)drawRect:(CGRect)rect{
[[UIColor blackColor] setStroke];
[path stroke];
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
CGPoint p=[touch locationInView:self];
[path moveToPoint:p];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[touches anyObject];
CGPoint p=[touch locationInView:self];
[path addLineToPoint:p];
[self setNeedsDisplay]; …Run Code Online (Sandbox Code Playgroud) 使用CLLocation对象(内容例如纬度= 48.196169,经度= 11.620237),我尝试获取当前的城市和国家:
if(!geocoder) {
geocoder = [[CLGeocoder alloc] init];
}
if (geocoder.geocoding) [geocoder cancelGeocode];
[geocoder reverseGeocodeLocation:lo completionHandler:^(NSArray *placemarks, NSError *error) {
if(devMode) {
NSLog(@"Found placemarks: %@, error: %@", placemarks, error);
}
if (error == nil && [placemarks count] > 0) {
// MY CODE - here placemarks is always (null)
} else {
if(devMode)
NSLog(@"%@", error.debugDescription);
}
}];
Run Code Online (Sandbox Code Playgroud)
大多数情况下,这很有效.但在极少数情况下,我只是得到错误:
PBRequester失败,错误错误域= NSURLErrorDomain代码= -1000"UngültigeURL"UserInfo = 0x16f5ff30 {NSUnderlyingError = 0x16f57810"UngültigeURL",NSLocalizedDescription =UngültigeURL}
找到地标:(null),错误:错误Domain = kCLErrorDomain Code = 2"操作无法完成.(kCLErrorDomain error 2.)"
我完全不知道为什么会这样.
在Objective-C中,我使用以下代码将自定义类序列化为一个工作正常的字典.为了熟悉Swift,将Objective-C代码移植到Swift.但是我无法实现这一点,我如何使用Swift实现这一目标?
这就是我用Objective-C实现的方法
.h
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface NSObject (aClass_NSDictionary)
- (NSDictionary *)NSDictionaryFromClass;
@end
.m
@implementation NSObject (aClass_NSDictionary)
- (NSDictionary *)NSDictionaryFromClass {
Class aClass = [self class];
u_int propertiesCount;
objc_property_t *propertiesInAClass = class_copyPropertyList(aClass, &propertiesCount);
NSMutableDictionary *propertiesDictionary = [[NSMutableDictionary alloc] initWithCapacity:propertiesCount];
for (int i = 0; i < propertiesCount; i++)
{
NSString *strAKey = [NSString stringWithCString:property_getName(propertiesInAClass[i])
encoding:NSUTF8StringEncoding];
[propertiesDictionary setValue:[self valueForKey:strAKey]
forKey:strAKey];
}
free(propertiesInAClass);
return propertiesDictionary;
}
@end
Run Code Online (Sandbox Code Playgroud)
当我在swift中编写相同的代码时,我无法找到相同的代码[self class].
class class2dicti : NSObject {
class func nsdictionaryFromAClass() -> NSDictionary …Run Code Online (Sandbox Code Playgroud) 我在斯威夫特做一个游戏.我希望能够使用GameCenter发布用户的分数,以便可以看到所有用户的分数.但是,我花了一天时间试图弄清楚如何做到这一点,但我没有找到任何有用的指示.
我对iOS编程和Swift都很陌生,而且关于这个主题的信息非常少,所有这些都是用Objective-C编写的.
任何人都可以帮我将GameCenter集成到我的应用程序中,这样我就可以将用户分数发布到排行榜上供人们查看吗?
编辑:我已经在iTunesConnect上创建了一个GameCenter排行榜.
编辑2:我尝试过以下教程:http://www.appcoda.com/ios-game-kit-framework/并将其转换为Swift.我转换了这个:
-(void)authenticateLocalPlayer {
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil) {
[self presentViewController:viewController animated:YES completion:nil];
}
else{
if ([GKLocalPlayer localPlayer].authenticated) {
_gameCenterEnabled = YES;
// Get the default leaderboard identifier.
[[GKLocalPlayer localPlayer] loadDefaultLeaderboardIdentifierWithCompletionHandler:^(NSString *leaderboardIdentifier, NSError *error) {
if (error != nil) {
NSLog(@"%@", [error localizedDescription]);
}
else{
_leaderboardIdentifier = leaderboardIdentifier;
}
}];
}
else {
_gameCenterEnabled = NO;
}
}
};
}
Run Code Online (Sandbox Code Playgroud)
进入这个:
func …Run Code Online (Sandbox Code Playgroud) ios ×8
ios7 ×2
objective-c ×2
swift ×2
autolayout ×1
clgeocoder ×1
cllocation ×1
game-center ×1
ios8 ×1
nsdictionary ×1
search ×1
uialertview ×1
uidatepicker ×1
uitabbaritem ×1
uitableview ×1
uiview ×1
xcode ×1
xcode5 ×1