当前位置: 首页>>代码示例>>C#>>正文


C# UIFont.GetLength方法代码示例

本文整理汇总了C#中UIFont.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# UIFont.GetLength方法的具体用法?C# UIFont.GetLength怎么用?C# UIFont.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIFont的用法示例。


在下文中一共展示了UIFont.GetLength方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WrapString

	public static string WrapString(string text, UIFont uiFont, float wrapLength, int size){
		
		
		sb.Length = 0;  //Clear does not exist in .net2.0, so we set length to 0
		
		float currentLength = 0;
		int lastStart = 0;
		int lastSpace = -1;
		bool isHTML = false;

		//We iterate over all characters in the string
		for (int i = 0; i< text.Length; i++){
			char currentChar = text[i];
			bool forceBreak = false;
			bool terminate = false;
			//This allows the formatting to accept newline characters in the input text
			if(currentChar == HTMLStart){
				isHTML = true;	
			}
			if(currentChar == HTMLEnd){
				isHTML = false;	
			}
			
			if(isHTML){
				// currentLength remains the same
			}
			else{
				if(currentChar == NewLine){
					
					lastSpace = i;
					forceBreak = true;
				}
				else{
					//If we arent already flagged for a new line, keep track of the most recent space character
					if(currentChar == Space){
						lastSpace = i;
					}
					currentLength += size*uiFont.GetLength(currentChar);
				}
			}
			
			//if we've reached the end, we need to write remaining text without a break
			if (i==text.Length-1){
				lastSpace = i;
				terminate = true;
			}
			
			//If we have exceeded the length, or forced a line break
			if(  (currentLength > wrapLength) || forceBreak || terminate){
				
				//We only add the 1 if the last character isn't a space or newline
				int count;
				
				
					if(currentChar == Space || currentChar == NewLine){
						count = lastSpace - lastStart;
					}
					else{
						count = lastSpace - lastStart+1;	
					}
				
				
				if(count < 1){
//					Debug.LogError("wrap failed" + count);	
					//currentLength = 0;
				}
				else{  //break a line - can we justify it here?
									
					
					sb.Append(text, lastStart, count);
					if(!terminate){
						sb.Append(NewLine);
					}
					//reset position to next character after lastSpace
					i = lastSpace +1;
					lastStart = i;
					currentLength = 0;
					

				}
			}
			
		}
		return sb.ToString();

	}
开发者ID:ivhpMX,项目名称:new-york,代码行数:86,代码来源:UIString.cs


注:本文中的UIFont.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。