Skip to content

Instantly share code, notes, and snippets.

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
//限制只能輸入10個字
let characterCountLimit = 10
//每次輸入一個character時,原本textField中的字數長度
let startingLength = textField.text?.characters.count ?? 0
//每次輸入一個character時,新輸入的字數長度
let lengthToAdd = string.characters.count
//每次輸入一個character時,需要被替換掉的字數長度
let lengthToReplace = range.length
let label = UILabel(frame:CGRect(x: 30, y: 30, width: 300, height: 60))
view.addSubview(label)
let attrString = NSMutableAttributedString(string: "問世間情為何物,直教生死相許。")
attrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.blue, range:NSRange(location: 0, length: 7))
attrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range:NSRange(location: 7, length: 8))
attrString.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 12), range:NSRange(location: 0, length: 7))
attrString.addAttribute(NSFontAttributeName, value: UIFont.systemFont(ofSize: 16), range:NSRange(location: 7, length: 8))
label.attributedText = attrString
@hatoto
hatoto / cri.java
Created November 4, 2016 07:38
use hibernate cirteria subquery
SessionFactory session = this.getHibernateTemplate().getSessionFactory();
Criteria companyCri = session.getCurrentSession().createCriteria(AgentCompany.class, "ac");
DetachedCriteria hotelCri = DetachedCriteria.forClass(Hotel.class,"ho");
companyCri.add(Restrictions.eq("isSupplier", isValid));
hotelCri.add(Property.forName("ho.agentCompany.id").eqProperty("ac.id"));
companyCri.add(Subqueries.exists(hotelCri.setProjection(Projections.property("ho.hotelId"))));
// 做為參數的function, 將兩個傳入的參數整數相加並return
func addTwoNumbers(numberA: Int, numberB: Int) -> Int {
return numberA + numberA
}
// 建立另一個function,有三個參數
// 型別為1. (Int, Int) -> Int 的函式,
// 2.Int,
// 3.Int
func printCalcResult(_ mathFunc: (Int, Int) -> Int, _ a : Int, _ b : Int) {
@IBOutlet weak var questionLabel: UILabel!
@IBOutlet weak var answerLabel: UILabel!
@IBAction func doShowAns(_ sender: AnyObject) {
answerLabel.text = quizArray[quizNumber].ans
}
@IBAction func nextQ(_ sender: AnyObject) {
if quizNumber < 9 {
quizNumber = quizNumber + 1
<td style="width: 110px;" class="lineLeft pl10">
<a href="javascript:void(0);"
onclick="submitWithValue('receivableListId', '<s:property value="compareRightSizeObject.receivableListId" />', this, '<s:url value="/accounting/accountPayment/detailMultipleReceivable" />', '_blank')" class='underline'>
<s:property value='compareRightSizeObject.payableListId' />
</a>
</td>
<td style="width: 178px;"><s:property value="'compareRightSizeObject.receivableAgentName" /></td>
<td style="width: 110px;"><s:date name="compareRightSizeObject.receivableDeadline" format="yyyy/MM/dd" /></td>
<td style="width: 90px;" class="align-right pr10">
<s:property value="compareRightSizeObject.receivablePrices.price" />
@hatoto
hatoto / homework_06.swift
Created October 19, 2016 04:31
swift practice
/*
*【題目】奇數行的數字總合, 定義function,接受2個參數,分別代表行數和列數。
*/
var sum = 0
func makeANumber(row: Int , column : Int) -> Int{
return row * column
}
for i in 0 ... 7 where i % 2 != 0{
/*
* 第二題
* 奇數行的數字總和
*/
let row1 : Array = [0,1,2,3,4,5,6,7]
var totalSum: Int! = 0
for i in 0...7{
if( (i % 2) == 1){ //是奇數行才進行
var oddRow = row1.map{ (x) -> Int in return x * i}
for j in oddRow{
@hatoto
hatoto / homework_01.swift
Last active October 19, 2016 03:25
swift_playground_practice
/*
* 算全部格子總和 ver.1
*/
let row0 : Array = [0,0,0,0,0,0,0,0]
let row1 : Array = [0,1,2,3,4,5,6,7]
let row2 : Array = [0,2,4,6,8,10,12,14]
let row3 : Array = [0,3,6,9,12,15,18,21]
let row4 : Array = [0,4,8,12,16,20,24,28]
let row5 : Array = [0,5,10,15,20,25,30,35]
let row6 : Array = [0,6,12,18,24,30,36,42]
@hatoto
hatoto / homework_04.swift
Last active October 19, 2016 03:10
swift_playground_practice
/*【題目】定義function,接受3個參數,起始值,最大值和決定數字倍數的number, 回傳運算結果 比方起始值3,
最大值98,決定數字倍數的number為5時,(只包含5的倍數) 運算結果為 5 + 10 + 15 + ….. + 95 */
//方式1: 每次加1
func addNumbers(startNum: Int, maxNum: Int, multipleNum: Int)->Int{
var totalSum : Int! = 0
for i in startNum ... maxNum {
if (i % 5) == 0 {
totalSum = totalSum + i