好吧所以我一直在阅读SO并做各种各样的谷歌搜索,但我无法弄清楚为什么我的字体不起作用.
我认为我已经做好了一切,但是当我运行应用程序时,我的按钮上的文字显示的是标准系统字体而不是我导入的字体.我添加NSLog(@"%@",[UIFont familyNames]);
以查看它是否在列表中,但它不是.这让我觉得我错了.
我希望有人可以帮我在自定义字体中显示标签中的文字. 感谢任何认为他们可能有任何建议的人!
这就是我所做的一步一步.
第1步:我从互联网上下载了.ttf文件.在我的发现者看起来像:
第2步:我将字体文件从finder拖入XCode并检查"将文件复制到项目文件夹"选项.所以在我的项目中,我可以看到:
第3步:我在字体书中打开字体,看看真正的文件名是什么,我看到了这个:
第4步:我在MyApp-Info.plist文件中添加了一个密钥,其中包含来自XCode的文件名,包括文件类型.它看起来像这样:
第5步:然后在我的代码中我写这个:
UIButton *thisLevelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[thisLevelButton setBackgroundImage:[UIImage imageNamed:@"ccLSButtonPlayed"] forState:UIControlStateNormal];
thisLevelButton.frame = CGRectMake(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
thisLevelButton.tag = j;
[thisLevelButton addTarget:self action:@selector(userSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
[thisLevelButton.titleLabel setFont:[UIFont fontWithName:@"PressStartK" size:24]];
[thisLevelButton setTitle:[NSString stringWithFormat:@"%i",(j+1)] forState:UIControlStateNormal];
// add the button to the panel
[subScroll addSubview:thisLevelButton];
Run Code Online (Sandbox Code Playgroud)
作为参考,这是打印在字体系列列表中的内容:
(
Thonburi,
"Snell Roundhand",
"Academy Engraved LET",
"Marker Felt",
"Geeza Pro",
"Arial Rounded MT Bold",
"Trebuchet MS",
Arial,
Marion,
"Gurmukhi MN", …
Run Code Online (Sandbox Code Playgroud) 我试图从命令行运行以下dot命令:
dot -v ~/Documents/FlowGraph/dot_sample_1_full.dot -Tpng 'Documents/FlowGraph/sampleOutput.png' -Ksfdp -Goverlap=false
Run Code Online (Sandbox Code Playgroud)
但这个输出失败了:
dot - graphviz version 2.36.0 (20140111.2315)
Using render: cairo:cairo
Using device: png:cairo:cairo
libdir = "/usr/local/lib/graphviz"
Activated plugin library: libgvplugin_neato_layout.6.dylib
Using layout: sfdp:neato_layout
The plugin configuration file:
/usr/local/lib/graphviz/config6
was successfully loaded.
render : cairo dot fig map pic pov ps quartz svg tk vml xdot
layout : circo dot fdp neato nop nop1 nop2 osage patchwork sfdp twopi
textlayout : textlayout
device : bmp canon cgimage cmap cmapx cmapx_np dot eps exr …
Run Code Online (Sandbox Code Playgroud) 我们目前有一个遗留的 Objective-C 框架,我们想在其中引入一些 Swift 组件。但是,我不知道如何从我们的 Swift 文件访问私有和项目范围的 Objective-C 文件。
我们已经使用伞头和模块映射文件来声明应包含在库模块中的公共头,并且我们希望将它们保留为唯一公开的文件。但是,我们的新 Swift 文件(在同一框架内)还需要访问我们不想公开的私有标头。
我已经尝试定义一个私有模块映射文件,其中列出了我想要使用的私有标头,然后使用 MODULEMAP_PRIVATE_FILE 构建设置指定它,但我不认为这达到了我们想要的效果。它似乎引入了一个新的 MyLibrary.Private 模块,该模块对外部目标(例如单元测试目标)公开可见,但仍然不可用于框架内的 Swift 文件。
任何关于如何实现这一点的建议,或者在其他项目中这样做的经验将不胜感激。
谢谢!
我正在为iphone创建一款益智游戏.我的所有菜单等都只是纵向,但我的游戏玩法可以是纵向或横向.
因此,当我在菜单中并且设备被保持在横向中时,那么当我进入游戏视图控制器时,它使用横向坐标进行布局,但屏幕实际上仍然是纵向的:
我想强制设备在进行布局之前重新定位屏幕.我怎么做?
现在我正在测试这样的设备方向:
- (void) viewDidLoad {
.
.
.
if (!UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
// Run Portrait Layout
}
else {
// Run Landscape Layout
}
}
Run Code Online (Sandbox Code Playgroud)
所以我知道该设备正在返回横向方向,但由于某种原因,屏幕仍然是纵向的.
我想编写一些自定义测试断言类型并将它们显示在 Xcode 中,类似于 XCTAssert() 失败的显示方式:
有没有办法让我连接到 Xcode 并实现这一点?
我希望我自己的断言函数在这里以相同的方式内联显示其错误:
到目前为止,我找到的最好的资源是 Apple 的 XCTest源代码,但我无法理解它是否包括负责显示错误 UI 的逻辑。
是否可以拥有一个自定义UIButton,其图像只覆盖其中的一半?我想它会是这样的:
UIButton *someButton = [UIButton buttonWithType:UIButtonTypeCustom];
[someButton setBackgroundImage:[UIImage imageNamed:@"buttonPicture"]];
/* Then there must be some property I can set that prevents the button from stretching the image?? */
.
.
.
Run Code Online (Sandbox Code Playgroud)
我希望有一个50x100px按钮,上半部分只有50x50px图像,下半部分透明.
我知道如何创建自定义按钮和一切.我只是想知道什么属性控制backgroundImage的拉伸.
谢谢!
我只是想绕着Grand Central Dispatch(GCD),我似乎无法找到答案
所以我知道通常你不应该从主线程以外的任何线程更新UIView元素.所以这是非法的:
dispatch_async(workerQueue, ^{
self.view.backgroundColor = [UIColor redColor];
});
Run Code Online (Sandbox Code Playgroud)
但是,在将视图元素实际添加到视图之前,您是否可以处理它们?换句话说,这是允许的吗?
dispatch_async(workerQueue, ^{
UIButton *thisLevelButton = [UIButton buttonWithType:UIButtonTypeCustom];
thisLevelButton.frame = CGRectMake(x, y, BUTTON_WIDTH, BUTTON_HEIGHT);
thisLevelButton.tag = kLevelButtonTags + j;
int levelState = [[[thisCat objectForKey:[levelNamesInCat objectAtIndex:j]] objectAtIndex:4] intValue];
[thisLevelButton setBackgroundImage:[UIImage imageNamed:@"ccLSButton50lock"]forState:UIControlStateNormal];
thisLevelButton.alpha = 0.5;
[thisLevelButton addTarget:self action:@selector(unlockButtonAction:) forControlEvents:UIControlEventTouchUpInside];
dispatch_async(dispatch_get_main_queue(), ^{
[self.view addSubview:thisLevelButton];
}
});
Run Code Online (Sandbox Code Playgroud) iphone multithreading objective-c grand-central-dispatch ios
我正在写一个益智游戏.当用户按下检查按钮时,我看他们输入的解决方案是否正确.根据结果,我为他们提供了两个行动表之一.现在我只有一些NSLog语句来确保调用的东西,但只有一个工作表似乎正常工作.
单击showErrorsActionSheet中的按钮时,不会调用任何内容.操作表从屏幕上消失,但日志从不打印.
我怀疑这与将两个动作表声明给同一个委托(自我)有关
- (void) checkSolution {
//code determines the value of the BOOL allCorrect
if (allCorrect) { //IF ALL OF THE LETTERS WERE CORRECT
//display UIAlertView;
NSLog(@"allCorrect");
UIActionSheet *levelCompleteActionSheet = [[UIActionSheet alloc] initWithTitle:@"Congratulations! You Have Finished the Level!" delegate:self cancelButtonTitle:@"Review my work" destructiveButtonTitle:@"Choose next puzzle" otherButtonTitles:nil, nil];
[levelCompleteActionSheet showInView:self.view];
[levelCompleteActionSheet release];
}
else {
//[self showIncorrectLettersInRed];
UIActionSheet *showErrorsActionSheet = [[UIActionSheet alloc] initWithTitle:@"Sorry, thats not right. Show errors in red?" delegate:self cancelButtonTitle:@"No Thanks, I'll keep trying" destructiveButtonTitle:@"Yes please, I'm …
Run Code Online (Sandbox Code Playgroud) 我收到以下错误:
阻止具有原点
https://<my host ip>
的帧访问具有原点的帧https://<target host ip>
.协议,域和端口必须匹配.
如果你发现两者都是'https'.但仍然会发生错误.请帮忙 - 我该如何避免这种情况.
如何制作这些按钮,以便一次只能使用一个?我运行顺便说一句,我现在没有得到任何错误.我只是在寻找解决方案来解决我的挑战.谢谢你的帮助
它们是在for循环中生成的,如下所示:
for (int l=0; l<list.length; l++) {
UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aButton setTag:l];
CGRect buttonRect = CGRectMake(11+charact*20, -40 + line*50, 18, 21);
aButton.frame = buttonRect;
[aButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[aButton setTitle:@" " forState:UIControlStateNormal];
[gameScroll addSubview:aButton];
}
Run Code Online (Sandbox Code Playgroud)
然后单击按钮时的操作是:
- (void) buttonClicked:(UIButton *)sender {
int tag = sender.tag;
if (sender.selected == TRUE) {
[sender setSelected:FALSE];
[sender setBackgroundColor:[UIColor clearColor]];
}
else if (sender.selected == FALSE) {
[sender setSelected:TRUE];
[sender setBackgroundColor:[UIColor redColor]];
}
}
Run Code Online (Sandbox Code Playgroud)
现在一切正常但我希望它知道是否已经选择了一个按钮并取消选择其他按钮,或者在用户点击该按钮范围之外的任何时候自动取消选择
提前致谢
在内存和计算时间方面,最好将int转换为:
int thisLetterInt = (int)[(NSNumber *)[levelSavedSolutionArrayFIX objectAtIndex:i] intValue];
Run Code Online (Sandbox Code Playgroud)
要么
int thisLetterInt = [[levelSavedSolutionArrayFIX objectAtIndex:i] intValue];
Run Code Online (Sandbox Code Playgroud)
还是完全相同?
另外,在任何一种情况下,我都不负责释放吗?
我在NSUserDefaults中将值设置为@"YES".当我运行这个方法时......
- (void) checkForHint {
NSLog(@"call:checkForHint");
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"valueForKeyInDefaults:%@",[defaults valueForKey:@"giveHint"]);
if ([defaults valueForKey:@"giveHint"] == @"YES") {
NSLog(@"need to give hint");
// replace a letter at random
int i=0;
bool found = NO;
while (!found && i<NUM_CHARACTERS_IN_LEVEL_STRING) {
NSLog(@"searching at index %i",i);
if ([buttons objectAtIndex:i] && 32==[[levelSavedSolutionArray objectAtIndex:i] intValue]) {
found = YES;
}
i++;
}
i--;
// We need to select all the buttons at this unsolved space
[self buttonClicked:[buttons objectAtIndex:i]];
// update the …
Run Code Online (Sandbox Code Playgroud) iphone ×7
ios ×6
objective-c ×6
xcode ×3
swift ×2
button ×1
casting ×1
command-line ×1
delegates ×1
dot ×1
equals ×1
fonts ×1
graphviz ×1
homebrew ×1
html ×1
iframe ×1
image ×1
ipad ×1
javascript ×1
label ×1
llvm ×1
optimization ×1
orientation ×1
rotation ×1
select ×1
string ×1
uibutton ×1
xctest ×1