我制作了一款iOS应用。一个视图具有Web视图和导航栏。导航栏出了问题。在iPhone 6s上,导航栏中的标题是“这是我的应用程序!”。但在iPhone 5s上,导航栏中的标题是“这是我的......”。这是因为iPhone 5s屏幕不像iPhone 6s加屏幕那么宽,所以我的标题太长了。
是否有可能自动缩小文本或为iPhone 5s(和其他设备)设置自己的字体大小或其他标题?
我几乎整天用Google搜索,但找不到任何有用的提示。 有人有想法吗?请帮帮我!
以下是iPhone 5s的屏幕截图:link
答案 0 :(得分:1)
试试这个:
label.adjustsLetterSpacingToFitWidth = true
你也可以试试这个:
#include <stdio.h>
#include <unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#define MAX_LINE 80
int main(void)
{
char *args[MAX_LINE/2+1];
int background= 0;//integer that acts a boolean for if & appears
int should_run = 1;
int status;
while(should_run)//Just to keep the interface going until the user chooses to stop
{
printf("osh>");//prompt
fflush(stdout);
int i = 0;
while(getchar() != '\n')//Use scanf until a new line is found
{
scanf("%s", &args[i]);
if(strcmp(&args[i], "exit") == 0)//temporary exit protocal
{
printf("Exiting now...");
return 0;
}
if(strcmp(&args[i], "&") == 0)//If we find a & in our input then we changed background to 1 or true
background = 1;
printf("Args[%i] = %s\n", i, &args[i]);//Tester
i++;
}
printf("Background = %i\n",background);//Test
pid_t pid= fork();// Create new child process
printf("process %i created\n", pid);//Test
if(pid < 0)//fork() failed
{
printf("Fork Failed.\n");
return 1;
}
else if(pid == 0)//Child process id
{
printf("Child process started %s command\n", &args[0]);
if(execvp(args[0], args) < 0)//change the current child process to execute the input given by the user
//with args[0] being the command and args being the parameters(ls -l is an example).
{
printf("Command failed\n");
}
return 0;
}
else//Parent Process
{
if(background == 1)//If the user typed in a & then the parent will wait for a change in state from the child, if there is no &
//then we will just finish the parent process
{
printf("Parent process waiting on child\n");
wait(NULL);
}
}
}
return 0;
答案 1 :(得分:0)
您可以使用以下示例。
NSDictionary *size = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"Arial" size:17.0], NSFontAttributeName, nil];
UINavigationController* navigationController = [self navigationController];
[navigationController.navigationBar setTitleTextAttributes:size];
答案 2 :(得分:0)
试试这个
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, YOUR_WIDH, YOUR_HEIGHT)];
lbl.textAlignment=NSTextAlignmentCenter;
lbl.backgroundColor=[UIColor clearColor];
lbl.font=[UIFont fontWithName:@"FONT_NAME" size:FONT_SIZE];
lbl.textColor=[UIColor whiteColor];
lbl.text=@"YOUR_TITLE";
self.navigationItem.titleView=lbl;
希望这有帮助。